Skip to content
This repository was archived by the owner on May 16, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions library/Zend/Validate/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -1264,22 +1264,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 tests/Zend/Validate/HostnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,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