Kaynağa Gözat

Merge pull request #470 from mhujer/62-validate-idn-email

Zend_Validate_EmailAddress: IDN domains are converted to punnycode if possible
Frank Brückner 11 yıl önce
ebeveyn
işleme
b32947c27d

+ 8 - 1
library/Zend/Validate/EmailAddress.php

@@ -449,7 +449,14 @@ class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
     private function _validateMXRecords()
     {
         $mxHosts = array();
-        $result = getmxrr($this->_hostname, $mxHosts);
+        $hostname = $this->_hostname;
+
+        //decode IDN domain name if possible
+        if (function_exists('idn_to_ascii')) {
+            $hostname = idn_to_ascii($this->_hostname);
+        }
+
+        $result = getmxrr($hostname, $mxHosts);
         if (!$result) {
             $this->_error(self::INVALID_MX_RECORD);
         } else if ($this->_options['deep'] && function_exists('checkdnsrr')) {

+ 13 - 0
tests/Zend/Validate/EmailAddressTest.php

@@ -622,6 +622,19 @@ class Zend_Validate_EmailAddressTest extends PHPUnit_Framework_TestCase
         $hostname = $this->_validator->getHostnameValidator();
         $this->assertTrue($hostname instanceof Zend_Validate_Hostname);
     }
+
+    /**
+     * @group GH-62
+     */
+    public function testIdnHostnameInEmaillAddress()
+    {
+        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+            $this->markTestSkipped('idn_to_ascii() is available in intl in PHP 5.3.0+');
+        }
+        $validator = new Zend_Validate_EmailAddress();
+        $validator->setValidateMx(true);
+        $this->assertTrue($validator->isValid('testmail@detrèsbonsdomaines.com'));
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Validate_EmailAddressTest::main') {