From 4b4568530641b1ceb67fe9245dfdda04fce8eff1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 11 Mar 2020 09:13:51 +0100 Subject: [PATCH] [HttpClient] fix requests to hosts that idn_to_ascii() cannot handle --- .../Component/HttpClient/HttpClientTrait.php | 5 +---- .../HttpClient/Test/HttpClientTestCase.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpClient/HttpClientTrait.php b/src/Symfony/Component/HttpClient/HttpClientTrait.php index 3eeb52fdd5ce..bace40a117da 100644 --- a/src/Symfony/Component/HttpClient/HttpClientTrait.php +++ b/src/Symfony/Component/HttpClient/HttpClientTrait.php @@ -441,10 +441,7 @@ private static function parseUrl(string $url, array $query = [], array $allowedS throw new InvalidArgumentException(sprintf('Unsupported IDN "%s", try enabling the "intl" PHP extension or running "composer require symfony/polyfill-intl-idn".', $host)); } - if (false === $host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : strtolower($host)) { - throw new InvalidArgumentException(sprintf('Unsupported host in "%s".', $url)); - } - + $host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) ?: strtolower($host) : strtolower($host); $host .= $port ? ':'.$port : ''; } diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index de13686819fc..8e61f801aaac 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -703,6 +703,23 @@ public function testResolve() $client->request('GET', 'http://symfony.com:8057/', ['timeout' => 1]); } + public function testIdnResolve() + { + $client = $this->getHttpClient(__FUNCTION__); + + $response = $client->request('GET', 'http://0-------------------------------------------------------------0.com:8057/', [ + 'resolve' => ['0-------------------------------------------------------------0.com' => '127.0.0.1'], + ]); + + $this->assertSame(200, $response->getStatusCode()); + + $response = $client->request('GET', 'http://Bücher.example:8057/', [ + 'resolve' => ['xn--bcher-kva.example' => '127.0.0.1'], + ]); + + $this->assertSame(200, $response->getStatusCode()); + } + public function testNotATimeout() { $client = $this->getHttpClient(__FUNCTION__);