Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/Hostname.php
Expand Up @@ -635,22 +635,19 @@ public function isValid($value)
*/
protected function decodePunycode($encoded)
{
$found = preg_match('/([^a-z0-9\x2d]{1,10})$/i', $encoded);
if (empty($encoded) || ($found > 0)) {
// no punycode encoded string, return as is
if (!preg_match('/^[a-z0-9-]+$/i', $encoded)) {
// no punycode encoded string
$this->error(self::CANNOT_DECODE_PUNYCODE);
return false;
}

$decoded = array();
$separator = strrpos($encoded, '-');
if ($separator > 0) {
for ($x = 0; $x < $separator; ++$x) {
// prepare decoding matrix
$decoded[] = ord($encoded[$x]);
}
} else {
$this->error(self::CANNOT_DECODE_PUNYCODE);
return false;
}

$lengthd = count($decoded);
Expand Down
2 changes: 1 addition & 1 deletion test/HostnameTest.php
Expand Up @@ -312,7 +312,7 @@ public function testPunycodeDecoding()

// Check TLD matching
$valuesExpected = array(
array(true, array('xn--brger-kva.com')),
array(true, array('xn--brger-kva.com', 'xn--eckwd4c7cu47r2wf.jp')),
array(false, array('xn--brger-x45d2va.com', 'xn--bürger.com', 'xn--'))
);
foreach ($valuesExpected as $element) {
Expand Down

0 comments on commit f8b9e58

Please sign in to comment.