Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit b32947c

Browse files
committed
Merge pull request zendframework#470 from mhujer/62-validate-idn-email
Zend_Validate_EmailAddress: IDN domains are converted to punnycode if possible
2 parents 40dd702 + c7a2727 commit b32947c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

library/Zend/Validate/EmailAddress.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,14 @@ private function _validateLocalPart()
449449
private function _validateMXRecords()
450450
{
451451
$mxHosts = array();
452-
$result = getmxrr($this->_hostname, $mxHosts);
452+
$hostname = $this->_hostname;
453+
454+
//decode IDN domain name if possible
455+
if (function_exists('idn_to_ascii')) {
456+
$hostname = idn_to_ascii($this->_hostname);
457+
}
458+
459+
$result = getmxrr($hostname, $mxHosts);
453460
if (!$result) {
454461
$this->_error(self::INVALID_MX_RECORD);
455462
} else if ($this->_options['deep'] && function_exists('checkdnsrr')) {

tests/Zend/Validate/EmailAddressTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,19 @@ public function testNotSetHostnameValidator()
622622
$hostname = $this->_validator->getHostnameValidator();
623623
$this->assertTrue($hostname instanceof Zend_Validate_Hostname);
624624
}
625+
626+
/**
627+
* @group GH-62
628+
*/
629+
public function testIdnHostnameInEmaillAddress()
630+
{
631+
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
632+
$this->markTestSkipped('idn_to_ascii() is available in intl in PHP 5.3.0+');
633+
}
634+
$validator = new Zend_Validate_EmailAddress();
635+
$validator->setValidateMx(true);
636+
$this->assertTrue($validator->isValid('testmail@detrèsbonsdomaines.com'));
637+
}
625638
}
626639

627640
if (PHPUnit_MAIN_METHOD == 'Zend_Validate_EmailAddressTest::main') {

0 commit comments

Comments
 (0)