Skip to content

Commit

Permalink
[HttpClient] fix requests to hosts that idn_to_ascii() cannot handle
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 11, 2020
1 parent 14b825b commit 4b45685
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/Symfony/Component/HttpClient/HttpClientTrait.php
Expand Up @@ -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 : '';
}

Expand Down
17 changes: 17 additions & 0 deletions src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php
Expand Up @@ -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__);
Expand Down

0 comments on commit 4b45685

Please sign in to comment.