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
-------
55831a85db
Fix Query URL
This commit is contained in:
commit
d9f490a8b2
@ -436,6 +436,10 @@ trait HttpClientTrait
|
||||
$url['path'] = '/';
|
||||
}
|
||||
|
||||
if ('?' === ($url['query'] ?? '')) {
|
||||
$url['query'] = null;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
@ -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' => '']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user