Skip to content

Commit

Permalink
Fixes zendframework#193 : use INTL_IDNA_VARIANT_UTS46 constant only w…
Browse files Browse the repository at this point in the history
…hen exists
  • Loading branch information
samsonasik committed Aug 19, 2017
1 parent 33caf7f commit 6121d4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 6 additions & 3 deletions bin/update_hostname_validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 6121d4f

Please sign in to comment.