Parcourir la source

[ZF-6676] Zend_Validate_Hostname:

- IP adresses are not checked when non-ip adress characters are involved
  as we then can assume that the given hostname is no IP adress

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15596 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas il y a 16 ans
Parent
commit
2903bf2df0
2 fichiers modifiés avec 10 ajouts et 7 suppressions
  1. 2 1
      library/Zend/Validate/Hostname.php
  2. 8 6
      tests/Zend/Validate/HostnameTest.php

+ 2 - 1
library/Zend/Validate/Hostname.php

@@ -419,7 +419,8 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         $this->_setValue($valueString);
 
         // Check input against IP address schema
-        if ($this->_ipValidator->setTranslator($this->getTranslator())->isValid($valueString)) {
+        if (preg_match('/^[0-9.a-e:.]*$/i', $valueString, $nothing) &&
+            $this->_ipValidator->setTranslator($this->getTranslator())->isValid($valueString)) {
             if (!($this->_allow & self::ALLOW_IP)) {
                 $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
                 return false;

+ 8 - 6
tests/Zend/Validate/HostnameTest.php

@@ -268,21 +268,22 @@ class Zend_Validate_HostnameTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * Test changed with ZF-6676, as IP check is only involved when IP patterns match
+     *
      * @see ZF-2861
+     * @see ZF-6676
      */
-    public function testIpValidatorMessagesShouldBeTranslated()
+    public function testValidatorMessagesShouldBeTranslated()
     {
-        require_once 'Zend/Validate/Ip.php';
-        $ipValidator = new Zend_Validate_Ip();
         require_once 'Zend/Translate.php';
         $translations = array(
-            'notIpAddress' => 'this is the IP error message',
+            'hostnameInvalidLocalName' => 'this is the IP error message',
         );
         $translator = new Zend_Translate('array', $translations);
-        $this->_validator->setTranslator($translator)->setIpValidator($ipValidator);
+        $this->_validator->setTranslator($translator);
 
         $this->_validator->isValid('0.239,512.777');
-        $messages = $ipValidator->getMessages();
+        $messages = $this->_validator->getMessages();
         $found = false;
         foreach ($messages as $code => $message) {
             if (array_key_exists($code, $translations)) {
@@ -290,6 +291,7 @@ class Zend_Validate_HostnameTest extends PHPUnit_Framework_TestCase
                 break;
             }
         }
+
         $this->assertTrue($found);
         $this->assertEquals($translations[$code], $message);
     }