Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better defaults for PHP installations with old ICU lib #2454

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Better defaults for PHP installations with old ICU lib
  • Loading branch information
alexeyshockov committed Dec 12, 2019
commit c63379edaad8af790be9e3bbd3d40d4eaae4e30c
2 changes: 1 addition & 1 deletion docs/request-options.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')
||
version_compare(PHP_VERSION, '7.2.0') < 0
alexeyshockov marked this conversation as resolved.
Show resolved Hide resolved
);

// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.

Expand Down