Skip to content

Commit

Permalink
bug #36023 [HttpClient] fix requests to hosts that idn_to_ascii() can…
Browse files Browse the repository at this point in the history
…not handle (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] fix requests to hosts that idn_to_ascii() cannot handle

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35852
| License       | MIT
| Doc PR        | -

Commits
-------

4b45685 [HttpClient] fix requests to hosts that idn_to_ascii() cannot handle
  • Loading branch information
nicolas-grekas committed Mar 12, 2020
2 parents c3eb70d + 4b45685 commit 26b123d
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 26b123d

Please sign in to comment.