File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ public function validate(string $host): Host
27
27
28
28
$ tld = $ this ->getTld ($ host ->exploded ());
29
29
30
- if ($ this ->verifyTld ($ tld )) {
31
- $ host ->tld ($ tld );
30
+ if ($ tld !== null ) {
31
+ if ($ this ->verifyTld ($ tld )) {
32
+ $ host ->tld ($ tld );
33
+ }
32
34
}
33
35
34
36
return $ host ;
@@ -51,18 +53,18 @@ public function tld(string $host): string
51
53
/**
52
54
* @param array<string> $parts
53
55
*/
54
- protected function getTld (array $ parts , ?string $ tld = null ): string
56
+ protected function getTld (array $ parts , bool $ partialFound = false , ?string $ tld = null ): ? string
55
57
{
56
58
$ current = end ($ parts ) . ($ tld ? ". {$ tld }" : '' );
57
59
unset($ parts [count ($ parts ) - 1 ]);
58
60
59
61
foreach ($ this ->publicSuffixList as $ key => $ item ) {
60
62
if (preg_match ('/\b ' . preg_quote ($ current ) . '\b/i ' , $ item ) === 1 ) {
61
- return $ this ->getTld ($ parts , $ current );
63
+ return $ this ->getTld ($ parts , true , $ current );
62
64
}
63
65
}
64
66
65
- return strval ($ tld );
67
+ return $ partialFound ? strval ($ tld ) : null ;
66
68
}
67
69
68
70
protected function verifyTld (string $ tld ): bool
You can’t perform that action at this time.
0 commit comments