From bba27664f48f2b4a1c4544ca2610667f47b907c3 Mon Sep 17 00:00:00 2001 From: Dmitry Lukashin Date: Wed, 6 Jan 2016 21:32:12 +0300 Subject: [PATCH 1/2] Decode uppercase domains --- src/Punycode.php | 1 + tests/PunycodeTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Punycode.php b/src/Punycode.php index 07cd54c..89fb292 100644 --- a/src/Punycode.php +++ b/src/Punycode.php @@ -157,6 +157,7 @@ protected function encodePart($input) */ public function decode($input) { + $input = strtolower($input); $parts = explode('.', $input); foreach ($parts as &$part) { if (strpos($part, static::PREFIX) !== 0) { diff --git a/tests/PunycodeTest.php b/tests/PunycodeTest.php index b724ba3..1b624b6 100644 --- a/tests/PunycodeTest.php +++ b/tests/PunycodeTest.php @@ -32,6 +32,20 @@ public function testDecode($decoded, $encoded) $this->assertEquals($decoded, $result); } + /** + * Test decoding Punycode in uppercase + * + * @param string $decoded Decoded domain + * @param string $encoded Encoded domain + * @dataProvider domainNamesProvider + */ + public function testDecodeUppercase($decoded, $encoded) + { + $Punycode = new Punycode(); + $result = $Punycode->decode(strtoupper($encoded)); + $this->assertEquals($decoded, $result); + } + /** * Provide domain names containing the decoded and encoded names * From 93bf2e8d7fa976a27f3144f703371396643a1c02 Mon Sep 17 00:00:00 2001 From: Dmitry Lukashin Date: Wed, 6 Jan 2016 22:11:28 +0300 Subject: [PATCH 2/2] Encode uppercase domains --- src/Punycode.php | 1 + tests/PunycodeTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Punycode.php b/src/Punycode.php index 89fb292..c54adbd 100644 --- a/src/Punycode.php +++ b/src/Punycode.php @@ -73,6 +73,7 @@ public function __construct($encoding = 'UTF-8') */ public function encode($input) { + $input = mb_strtolower($input, $this->encoding); $parts = explode('.', $input); foreach ($parts as &$part) { $part = $this->encodePart($part); diff --git a/tests/PunycodeTest.php b/tests/PunycodeTest.php index 1b624b6..61902dc 100644 --- a/tests/PunycodeTest.php +++ b/tests/PunycodeTest.php @@ -32,6 +32,20 @@ public function testDecode($decoded, $encoded) $this->assertEquals($decoded, $result); } + /** + * Test encoding Punycode in uppercase + * + * @param string $decoded Decoded domain + * @param string $encoded Encoded domain + * @dataProvider domainNamesProvider + */ + public function testEncodeUppercase($decoded, $encoded) + { + $Punycode = new Punycode(); + $result = $Punycode->encode(mb_strtoupper($decoded, 'UTF-8')); + $this->assertEquals($encoded, $result); + } + /** * Test decoding Punycode in uppercase *