From b80aac7b6385ac6e65ec9d256319dc36601c3c2e Mon Sep 17 00:00:00 2001 From: Julien BERNARD Date: Wed, 17 Nov 2021 16:08:32 -0500 Subject: [PATCH] [HttpClient][Mime] Add correct IDN flags for IDNA2008 compliance --- HttpClientTrait.php | 2 +- Tests/HttpClientTraitTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/HttpClientTrait.php b/HttpClientTrait.php index 70df925..07bd717 100644 --- a/HttpClientTrait.php +++ b/HttpClientTrait.php @@ -456,7 +456,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)); } - $host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46) ?: strtolower($host) : strtolower($host); + $host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46) ?: strtolower($host) : strtolower($host); $host .= $port ? ':'.$port : ''; } diff --git a/Tests/HttpClientTraitTest.php b/Tests/HttpClientTraitTest.php index 0feccd2..40b099c 100644 --- a/Tests/HttpClientTraitTest.php +++ b/Tests/HttpClientTraitTest.php @@ -160,6 +160,8 @@ public function provideParseUrl(): iterable yield [[null, null, 'bar', '?a%5Bb%5Bc%5D=d', null], 'bar?a[b[c]=d', []]; yield [[null, null, 'bar', '?a%5Bb%5D%5Bc%5D=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]]; yield [[null, null, 'bar', '?a=b&a%5Bb%20c%5D=d&e%3Df=%E2%9C%93', null], 'bar?a=b', ['a' => ['b c' => 'd'], 'e=f' => '✓']]; + // IDNA 2008 compliance + yield [['https:', '//xn--fuball-cta.test', null, null, null], 'https://fußball.test']; } /**