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

Commit 52adc67

Browse files
committed
Merge branch 'feature/160' into develop
Close #160
2 parents 3414136 + 299cad6 commit 52adc67

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Diff for: CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ All notable changes to this project will be documented in this file, in reverse
4040

4141
### Fixed
4242

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

4547
## 2.9.2 - 2017-07-20
4648

Diff for: src/EmailAddress.php

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace Zend\Validator;
1111

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

@@ -360,6 +364,26 @@ protected function validateLocalPart()
360364
return $result;
361365
}
362366

367+
/**
368+
* @param string $localPart Address local part to validate.
369+
* @return bool
370+
*/
371+
protected function validateInternationalizedLocalPart($localPart)
372+
{
373+
if (extension_loaded('intl')
374+
&& false === UConverter::transcode($localPart, 'UTF-8', 'UTF-8')
375+
) {
376+
// invalid utf?
377+
return false;
378+
}
379+
380+
$atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d\x7e';
381+
// RFC 6532 extends atext to include non-ascii utf
382+
// @see https://tools.ietf.org/html/rfc6532#section-3.1
383+
$uatext = $atext . '\x{80}-\x{FFFF}';
384+
return (bool) preg_match('/^[' . $uatext . ']+(\x2e+[' . $uatext . ']+)*$/u', $localPart);
385+
}
386+
363387
/**
364388
* Returns the found MX Record information after validation including weight for further processing
365389
*

Diff for: test/EmailAddressTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ public function validEmailAddresses()
235235
];
236236

237237
if (extension_loaded('intl')) {
238+
$return['иван@письмо.рф'] = ['иван@письмо.рф'];
239+
$return['öäü@ä-umlaut.de'] = ['öäü@ä-umlaut.de'];
240+
$return['frédé[email protected]'] = ['frédé[email protected]'];
238241
$return['bob@тест.рф'] = ['bob@тест.рф'];
239242
240243
}
@@ -277,7 +280,6 @@ public function invalidEmailAddresses()
277280
'bob @ domain.com' => ['bob @ domain.com'],
278281
279282
280-
'иван@письмо.рф' => ['иван@письмо.рф'],
281283
'multiline' => ['bob
282284
283285
@domain.com'],

0 commit comments

Comments
 (0)