Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from abcdmitry/master
Browse files Browse the repository at this point in the history
Decoding uppercase domains as well
  • Loading branch information
renan committed Jan 7, 2016
2 parents b672918 + 93bf2e8 commit 8621111
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Punycode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -157,6 +158,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) {
Expand Down
28 changes: 28 additions & 0 deletions tests/PunycodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ 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
*
* @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
*
Expand Down

0 comments on commit 8621111

Please sign in to comment.