From c63379edaad8af790be9e3bbd3d40d4eaae4e30c Mon Sep 17 00:00:00 2001 From: Alexey Shokov Date: Thu, 12 Dec 2019 11:41:39 +0400 Subject: [PATCH 1/2] Better defaults for PHP installations with old ICU lib --- docs/request-options.rst | 2 +- src/Client.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/request-options.rst b/docs/request-options.rst index 2a477aee9..4e5117b60 100644 --- a/docs/request-options.rst +++ b/docs/request-options.rst @@ -561,7 +561,7 @@ idn_conversion :Types: - bool - int -:Default: ``true`` if ``intl`` extension is available, ``false`` otherwise +:Default: ``true`` if ``intl`` extension is available (and ICU library is 4.6+ for PHP 7.2+), ``false`` otherwise :Constant: ``GuzzleHttp\RequestOptions::IDN_CONVERSION`` .. code-block:: php diff --git a/src/Client.php b/src/Client.php index db4062f94..a9c851cf5 100644 --- a/src/Client.php +++ b/src/Client.php @@ -218,7 +218,8 @@ private function buildUri($uri, array $config) if ($uri->getHost() && isset($config['idn_conversion']) && ($config['idn_conversion'] !== false)) { $idnOptions = ($config['idn_conversion'] === true) ? IDNA_DEFAULT : $config['idn_conversion']; - $asciiHost = idn_to_ascii($uri->getHost(), $idnOptions, INTL_IDNA_VARIANT_UTS46, $info); + $idnaVariant = defined('INTL_IDNA_VARIANT_UTS46') ? INTL_IDNA_VARIANT_UTS46 : 0; + $asciiHost = idn_to_ascii($uri->getHost(), $idnOptions, $idnaVariant, $info); if ($asciiHost === false) { $errorBitSet = isset($info['errors']) ? $info['errors'] : 0; @@ -267,7 +268,14 @@ private function configureDefaults(array $config) ]; // idn_to_ascii() is a part of ext-intl and might be not available - $defaults['idn_conversion'] = function_exists('idn_to_ascii'); + $defaults['idn_conversion'] = function_exists('idn_to_ascii') + // Old ICU versions don't have this constant, so we are basically stuck (see https://github.com/guzzle/guzzle/pull/2424 + // and https://github.com/guzzle/guzzle/issues/2448 for details) + && ( + defined('INTL_IDNA_VARIANT_UTS46') + || + version_compare(PHP_VERSION, '7.2.0') < 0 + ); // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set. From 6a8a624477bb92c80f47ad5ca72a687b1b855ac4 Mon Sep 17 00:00:00 2001 From: Alexey Shokov Date: Thu, 12 Dec 2019 21:05:07 +0400 Subject: [PATCH 2/2] Faster PHP version comparison Co-Authored-By: Brandon Kelly --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index a9c851cf5..687358ed9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -274,7 +274,7 @@ private function configureDefaults(array $config) && ( defined('INTL_IDNA_VARIANT_UTS46') || - version_compare(PHP_VERSION, '7.2.0') < 0 + PHP_VERSION_ID < 70200 ); // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.