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..687358ed9 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') + || + PHP_VERSION_ID < 70200 + ); // Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.