Skip to content

Commit d9f490a

Browse files
committed
minor #40047 [HttpClient] Remove unnecessary "?" in url query (michaljusiega)
This PR was merged into the 5.3-dev branch. Discussion ---------- [HttpClient] Remove unnecessary "?" in url query | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | When creating the Request with passing nullable values as query parameters `HttpClientTrait::resolveUrl` method keeps at the end of URL "?" (IMO unnecessary) character. Before: ``` $client = HttpClient::create(); $response = $client->request('GET', 'http://example.com/', ['query' => ['a' => null]]); $url = $response->getInfo('url'); // http://example.com/? ``` After: ``` $client = HttpClient::create(); $response = $client->request('GET', 'http://example.com/', ['query' => ['a' => null]]); $url = $response->getInfo('url'); // http://example.com/ ``` Commits ------- 55831a8 Fix Query URL
2 parents 4537f85 + 55831a8 commit d9f490a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ private static function resolveUrl(array $url, ?array $base, array $queryDefault
436436
$url['path'] = '/';
437437
}
438438

439+
if ('?' === ($url['query'] ?? '')) {
440+
$url['query'] = null;
441+
}
442+
439443
return $url;
440444
}
441445

src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function providePrepareRequestUrl(): iterable
4444
yield ['http://example.com/?a=2&b=b', '.?a=2'];
4545
yield ['http://example.com/?a=3&b=b', '.', ['a' => 3]];
4646
yield ['http://example.com/?a=3&b=b', '.?a=0', ['a' => 3]];
47+
yield ['http://example.com/', 'http://example.com/', ['a' => null]];
48+
yield ['http://example.com/?b=', 'http://example.com/', ['b' => '']];
49+
yield ['http://example.com/?b=', 'http://example.com/', ['a' => null, 'b' => '']];
4750
}
4851

4952
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy