Skip to content

Commit

Permalink
Zend_Validate_EmailAddress: IDN domains are converted to punnycode if…
Browse files Browse the repository at this point in the history
… possible

Fixes zendframework#62
  • Loading branch information
mhujer committed Nov 29, 2014
1 parent 007f538 commit 419bfb0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/Zend/Validate/EmailAddress.php
Expand Up @@ -449,7 +449,14 @@ private function _validateLocalPart()
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')) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Zend/Validate/EmailAddressTest.php
Expand Up @@ -622,6 +622,19 @@ public function testNotSetHostnameValidator()
$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') {
Expand Down

0 comments on commit 419bfb0

Please sign in to comment.