소스 검색

Merge pull request #394 from fetus-hina/zf2-4636

Validate_Hostname: Punycode decoding fails if encoded string has not hyphen
Frank Brückner 11 년 전
부모
커밋
fabc5afd5d
2개의 변경된 파일4개의 추가작업 그리고 7개의 파일을 삭제
  1. 3 6
      library/Zend/Validate/Hostname.php
  2. 1 1
      tests/Zend/Validate/HostnameTest.php

+ 3 - 6
library/Zend/Validate/Hostname.php

@@ -1336,22 +1336,19 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
      */
     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);

+ 1 - 1
tests/Zend/Validate/HostnameTest.php

@@ -334,7 +334,7 @@ class Zend_Validate_HostnameTest extends PHPUnit_Framework_TestCase
 
         // 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) {