Skip to content

Commit 192f793

Browse files
committed
improve PublicSuffix validation
1 parent b8cb78e commit 192f793

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/PublicSuffix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __construct($publicSuffix = null, string $section = '')
100100
*/
101101
private function setSection(string $section): string
102102
{
103-
if (in_array($this->publicSuffix, ['', null], true)) {
103+
if (in_array($this->publicSuffix, ['', null], true) || '.' === substr($this->publicSuffix, -1, 1)) {
104104
return '';
105105
}
106106

tests/PublicSuffixTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,41 @@ public function testPSToUnicodeWithUrlEncode()
4848
$this->assertSame('bébe', (new PublicSuffix('b%C3%A9be'))->toUnicode()->getContent());
4949
}
5050

51+
/**
52+
* @covers ::__construct
53+
* @covers ::setLabels
54+
* @covers ::setSection
55+
* @covers ::isKnown
56+
* @covers ::isICANN
57+
* @covers ::isPrivate
58+
* @dataProvider PSProvider
59+
*
60+
* @param string|null $publicSuffix
61+
* @param string $section
62+
* @param bool $isKnown
63+
* @param bool $isIcann
64+
* @param bool $isPrivate
65+
*/
66+
public function testSetSection($publicSuffix, string $section, bool $isKnown, bool $isIcann, bool $isPrivate)
67+
{
68+
$ps = new PublicSuffix($publicSuffix, $section);
69+
70+
$this->assertSame($isKnown, $ps->isKnown());
71+
$this->assertSame($isIcann, $ps->isICANN());
72+
$this->assertSame($isPrivate, $ps->isPrivate());
73+
}
74+
75+
public function PSProvider()
76+
{
77+
return [
78+
[null, PublicSuffix::ICANN_DOMAINS, false, false, false],
79+
['', PublicSuffix::ICANN_DOMAINS, false, false, false],
80+
['foo', PublicSuffix::ICANN_DOMAINS, true, true, false],
81+
['foo', PublicSuffix::PRIVATE_DOMAINS, true, false, true],
82+
['foo.', PublicSuffix::PRIVATE_DOMAINS, false, false, false],
83+
];
84+
}
85+
5186
/**
5287
* @covers ::__construct
5388
* @covers ::setLabels

0 commit comments

Comments
 (0)