From b0ef856361a2598b1d24a251e05a0287d1426d80 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 20 Nov 2019 20:43:16 +0100 Subject: Old ICU: INTL_IDNA_VARIANT_2003 fallback (#2680) * Old ICU: INTL_IDNA_VARIANT_2003 fallback Fix https://github.com/FreshRSS/FreshRSS/issues/2676 Fix https://github.com/FreshRSS/FreshRSS/issues/2677 ICU version < 4.6: When INTL_IDNA_VARIANT_UTS46 is not available, use INTL_IDNA_VARIANT_2003 Cf. https://github.com/PrestaShop/PrestaShop/pull/11995 --- lib/lib_rss.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/lib_rss.php') diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 137c7f2d5..357c02e82 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -49,13 +49,19 @@ spl_autoload_register('classAutoloader'); function idn_to_puny($url) { if (function_exists('idn_to_ascii')) { - $parts = parse_url($url); - if (!empty($parts['host'])) { - $idn = $parts['host']; - $puny = idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46); + $idn = parse_url($url, PHP_URL_HOST); + if ($idn != '') { + // https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003 + if (defined('INTL_IDNA_VARIANT_UTS46')) { + $puny = idn_to_ascii($idn, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); + } elseif (defined('INTL_IDNA_VARIANT_2003')) { + $puny = idn_to_ascii($idn, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003); + } else { + $puny = idn_to_ascii($idn); + } $pos = strpos($url, $idn); - if ($pos !== false) { - return substr_replace($url, $puny, $pos, strlen($idn)); + if ($puny != '' && $pos !== false) { + $url = substr_replace($url, $puny, $pos, strlen($idn)); } } } -- cgit v1.2.3