Skip to content

Commit

Permalink
Merge pull request #2454 from alexeyshockov/idn-conversion-fix
Browse files Browse the repository at this point in the history
Better defaults for PHP installations with old ICU lib
  • Loading branch information
sagikazarmark committed Dec 18, 2019
2 parents fc34aad + 6a8a624 commit 2eda2b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/request-options.rst
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/Client.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit 2eda2b9

Please sign in to comment.