Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Zend_Validate_EmailAddress: IDN domains are converted to punnycode if possible #470

Merged
merged 1 commit into from
Jan 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion library/Zend/Validate/EmailAddress.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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