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

Commit

Permalink
Merge branch 'hotfix/4636'
Browse files Browse the repository at this point in the history
Close #4636
  • Loading branch information
weierophinney committed Jun 12, 2013
2 parents 70f5d71 + 80b1d6d commit d7038cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions library/Zend/Validator/Hostname.php
Original file line number Diff line number Diff line change
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 tests/ZendTest/Validator/HostnameTest.php
Original file line number Diff line number Diff line change
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 d7038cd

Please sign in to comment.