diff --git a/src/Symfony/Component/HttpClient/HttpClientTrait.php b/src/Symfony/Component/HttpClient/HttpClientTrait.php index cf439c6ff0..2d9de605bf 100644 --- a/src/Symfony/Component/HttpClient/HttpClientTrait.php +++ b/src/Symfony/Component/HttpClient/HttpClientTrait.php @@ -422,6 +422,10 @@ trait HttpClientTrait $url['path'] = '/'; } + if ('?' === ($url['query'] ?? '')) { + $url['query'] = null; + } + return $url; } diff --git a/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php b/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php index 0feccd22b7..d75dc0084a 100644 --- a/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php +++ b/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php @@ -44,6 +44,9 @@ class HttpClientTraitTest extends TestCase yield ['http://example.com/?a=2&b=b', '.?a=2']; yield ['http://example.com/?a=3&b=b', '.', ['a' => 3]]; yield ['http://example.com/?a=3&b=b', '.?a=0', ['a' => 3]]; + yield ['http://example.com/', 'http://example.com/', ['a' => null]]; + yield ['http://example.com/?b=', 'http://example.com/', ['b' => '']]; + yield ['http://example.com/?b=', 'http://example.com/', ['a' => null, 'b' => '']]; } /**