Skip to content

Commit b665c30

Browse files
committed
fix(validation): Also try to find the complete TLD when 1st part is not found.
1 parent df94eef commit b665c30

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Validator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ protected function getTld(array $parts, string $section, bool $partialFound = fa
5050
}
5151
}
5252

53+
if ($partialFound === false) {
54+
$current = end($parts) . '.' . $current;
55+
foreach ($this->publicSuffixList[$section] as $item) {
56+
if ($current === $item) {
57+
return $this->getTld(
58+
parts: $parts,
59+
section: $section,
60+
partialFound: true,
61+
tld: $current,
62+
);
63+
}
64+
}
65+
}
66+
5367
return $partialFound ? strval($tld) : null;
5468
}
5569

tests/Unit/ValidatorTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353
it("is same as $url", fn () => expect($host->original())->toBe($url));
5454
});
5555

56+
describe('Valid claudiatreagus.co.za', function () {
57+
$validator = getInstance();
58+
$url = 'https://claudiatreagus.co.za/';
59+
$host = $validator->validate($url);
60+
61+
it('is a valid domain', fn () => expect($host->isValid())->toBeTrue());
62+
it('is same domain', fn () => expect($host->domain())->toBe('claudiatreagus.co.za'));
63+
it("is same as $url", fn () => expect($host->original())->toBe($url));
64+
});
65+
5666
describe('Invalid *.adro.com', function () {
5767
$validator = getInstance();
5868
$url = 'https://*.adro.com';
@@ -77,4 +87,4 @@
7787

7888
it("$url is valid domain", fn () => expect($host->isValid())->toBeTrue());
7989
it("from $url - compass.com is the domain", fn () => expect($host->domain())->toBe('compass.com'));
80-
});
90+
});

0 commit comments

Comments
 (0)