File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,8 +27,10 @@ public function validate(string $host): Host
2727
2828 $ tld = $ this ->getTld ($ host ->exploded ());
2929
30- if ($ this ->verifyTld ($ tld )) {
31- $ host ->tld ($ tld );
30+ if ($ tld !== null ) {
31+ if ($ this ->verifyTld ($ tld )) {
32+ $ host ->tld ($ tld );
33+ }
3234 }
3335
3436 return $ host ;
@@ -51,18 +53,18 @@ public function tld(string $host): string
5153 /**
5254 * @param array<string> $parts
5355 */
54- protected function getTld (array $ parts , ?string $ tld = null ): string
56+ protected function getTld (array $ parts , bool $ partialFound = false , ?string $ tld = null ): ? string
5557 {
5658 $ current = end ($ parts ) . ($ tld ? ". {$ tld }" : '' );
5759 unset($ parts [count ($ parts ) - 1 ]);
5860
5961 foreach ($ this ->publicSuffixList as $ key => $ item ) {
6062 if (preg_match ('/\b ' . preg_quote ($ current ) . '\b/i ' , $ item ) === 1 ) {
61- return $ this ->getTld ($ parts , $ current );
63+ return $ this ->getTld ($ parts , true , $ current );
6264 }
6365 }
6466
65- return strval ($ tld );
67+ return $ partialFound ? strval ($ tld ) : null ;
6668 }
6769
6870 protected function verifyTld (string $ tld ): bool
You can’t perform that action at this time.
0 commit comments