From 6121d4f0af0272fd4f8621e779e8b120d232a80c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 19 Aug 2017 22:36:27 +0700 Subject: [PATCH 1/4] Fixes #193 : use INTL_IDNA_VARIANT_UTS46 constant only when exists --- bin/update_hostname_validator.php | 9 ++++++--- src/EmailAddress.php | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/update_hostname_validator.php b/bin/update_hostname_validator.php index 69043d681..593f73a09 100644 --- a/bin/update_hostname_validator.php +++ b/bin/update_hostname_validator.php @@ -177,9 +177,12 @@ function getNewValidTlds($string) function getPunycodeDecoder() { if (function_exists('idn_to_utf8')) { - return function ($domain) { - return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); - }; + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return function ($domain) { + return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); + }; + } + return 'idn_to_utf8'; } $hostnameValidator = new Hostname(); diff --git a/src/EmailAddress.php b/src/EmailAddress.php index bd58018dc..ab5e9db9b 100644 --- a/src/EmailAddress.php +++ b/src/EmailAddress.php @@ -554,7 +554,10 @@ public function isValid($value) protected function idnToAscii($email) { if (extension_loaded('intl')) { - return (idn_to_ascii($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email); + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return (idn_to_ascii($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email); + } + return (idn_to_ascii($email) ?: $email); } return $email; } @@ -577,7 +580,10 @@ protected function idnToUtf8($email) // the source string in those cases. // But not when the source string is long enough. // Thus we default to source string ourselves. - return idn_to_utf8($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email; + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return idn_to_utf8($email, 0, INTL_IDNA_VARIANT_UTS46) ?: $email; + } + return idn_to_utf8($email) ?: $email; } return $email; } From 96925c2e051728babd6c83f1fca3ba387c40631f Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 22 Aug 2017 09:17:00 -0500 Subject: [PATCH 2/4] Reverts changes to update_hostname_validator.php Reverts the changes introduced by 6121d4f to `bin/update_hostname_validator.php`, as they are unnecessary for that script; it is for maintainers and continuous integration, not consumers. --- bin/update_hostname_validator.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/update_hostname_validator.php b/bin/update_hostname_validator.php index 593f73a09..69043d681 100644 --- a/bin/update_hostname_validator.php +++ b/bin/update_hostname_validator.php @@ -177,12 +177,9 @@ function getNewValidTlds($string) function getPunycodeDecoder() { if (function_exists('idn_to_utf8')) { - if (defined('INTL_IDNA_VARIANT_UTS46')) { - return function ($domain) { - return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); - }; - } - return 'idn_to_utf8'; + return function ($domain) { + return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); + }; } $hostnameValidator = new Hostname(); From 15a9ac87e2a63cf3ca22e813952f2a805f1417fc Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 22 Aug 2017 09:18:54 -0500 Subject: [PATCH 3/4] Adds CHANGELOG for #194 --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bd298936..9362e898b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.10.1 - TBD +## 2.10.1 - 2017-08-22 ### Added @@ -22,7 +22,10 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#194](https://github.com/zendframework/zend-validator/pull/194) modifies the + `EmailAddress` validator to omit the `INTL_IDNA_VARIANT_UTS46` flag to + `idn_to_utf8()` if the constant is not defined, fixing an issue on systems + using pre-2012 releases of libicu. ## 2.10.0 - 2017-08-14 From 11307eae758c03881d73dbe9bfcb18fb88159021 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 22 Aug 2017 09:19:17 -0500 Subject: [PATCH 4/4] Updates TLD definitions for Hostname validator --- src/Hostname.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hostname.php b/src/Hostname.php index 1f995206d..f30c35f7b 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -69,7 +69,7 @@ class Hostname extends AbstractValidator /** * Array of valid top-level-domains - * IanaVersion 2017081400 + * IanaVersion 2017082200 * * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain * @see http://www.iana.org/domains/root/db/ Official list of supported TLDs