Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/160' into develop
Browse files Browse the repository at this point in the history
Close #160
  • Loading branch information
weierophinney committed Jul 26, 2017
2 parents 3414136 + 299cad6 commit 52adc67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#160](https://github.com/zendframework/zend-validator/pull/160) fixes how the
`EmailAddress` validator handles the local part of an address, allowing it to
support unicode.

## 2.9.2 - 2017-07-20

Expand Down
24 changes: 24 additions & 0 deletions src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Zend\Validator;

use UConverter;

class EmailAddress extends AbstractValidator
{
const INVALID = 'emailAddressInvalid';
Expand Down Expand Up @@ -342,6 +344,8 @@ protected function validateLocalPart()
$atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e';
if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->localPart)) {
$result = true;
} elseif ($this->validateInternationalizedLocalPart($this->localPart)) {
$result = true;
} else {
// Try quoted string format (RFC 5321 Chapter 4.1.2)

Expand All @@ -360,6 +364,26 @@ protected function validateLocalPart()
return $result;
}

/**
* @param string $localPart Address local part to validate.
* @return bool
*/
protected function validateInternationalizedLocalPart($localPart)
{
if (extension_loaded('intl')
&& false === UConverter::transcode($localPart, 'UTF-8', 'UTF-8')
) {
// invalid utf?
return false;
}

$atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e';
// RFC 6532 extends atext to include non-ascii utf
// @see https://tools.ietf.org/html/rfc6532#section-3.1
$uatext = $atext . '\x{80}-\x{FFFF}';
return (bool) preg_match('/^[' . $uatext . ']+(\x2e+[' . $uatext . ']+)*$/u', $localPart);
}

/**
* Returns the found MX Record information after validation including weight for further processing
*
Expand Down
4 changes: 3 additions & 1 deletion test/EmailAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public function validEmailAddresses()
];

if (extension_loaded('intl')) {
$return['иван@письмо.рф'] = ['иван@письмо.рф'];
$return['öäü@ä-umlaut.de'] = ['öäü@ä-umlaut.de'];
$return['frédé[email protected]'] = ['frédé[email protected]'];
$return['bob@тест.рф'] = ['bob@тест.рф'];
$return['[email protected]'] = ['[email protected]'];
}
Expand Down Expand Up @@ -277,7 +280,6 @@ public function invalidEmailAddresses()
'bob @ domain.com' => ['bob @ domain.com'],
'[email protected]' => ['[email protected]'],
'"bob%[email protected]' => ['"bob%[email protected]'],
'иван@письмо.рф' => ['иван@письмо.рф'],
'multiline' => ['bob
@domain.com'],
Expand Down

0 comments on commit 52adc67

Please sign in to comment.