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

Fixes #193 : use INTL_IDNA_VARIANT_UTS46 constant only when exists #194

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to do the check here, as this script is only executed by maintainers and by Travis (which has an up-to-date libicu already).

}

$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