Skip to content

Commit fc579c0

Browse files
committed
Improve domain conversion
1 parent 47281ed commit fc579c0

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/IDNAConverterTrait.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ private static function getIdnErrors(int $error_bit): string
7171
*/
7272
private function idnToAscii(string $host): string
7373
{
74-
if (false !== strpos($host, 'xn--')) {
74+
if (false !== strpos($host, '%')) {
75+
$host = rawurldecode($host);
76+
}
77+
78+
if (!preg_match('/[\pL]+/u', $host)) {
7579
return $host;
7680
}
7781

@@ -95,6 +99,10 @@ private function idnToAscii(string $host): string
9599
*/
96100
private function idnToUnicode(string $host): string
97101
{
102+
if (false !== strpos($host, '%')) {
103+
$host = $this->idnToAscii($host);
104+
}
105+
98106
if (false === strpos($host, 'xn--')) {
99107
return $host;
100108
}

src/Rules.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ private function findPublicSuffix(string $domain, string $section): PublicSuffix
220220
*/
221221
private function normalizeDomain(string $domain): string
222222
{
223-
if (false !== strpos($domain, '%')) {
224-
$domain = rawurldecode($domain);
225-
}
226-
227223
try {
228224
return strtolower($this->idnToAscii($domain));
229225
} catch (Exception $e) {

tests/PublicSuffixTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public function testDomainInternalPhpMethod()
1818
$this->assertEquals($publicSuffix, $generatePublicSuffix);
1919
}
2020

21+
public function testPSToUnicodeWithUrlEncode()
22+
{
23+
$this->assertSame('bébe', (new PublicSuffix('b%C3%A9be'))->toUnicode()->getContent());
24+
}
25+
2126
public function testPSToAsciiThrowsException()
2227
{
2328
$this->expectException(Exception::class);

0 commit comments

Comments
 (0)