Skip to content

Commit e2986ab

Browse files
committed
fix: Only retun tld if really found in the list.
1 parent e170548 commit e2986ab

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Validator.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)