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:
Fabien Potencier 2021-02-01 16:03:21 +01:00
commit d9f490a8b2
2 changed files with 7 additions and 0 deletions

View File

@ -436,6 +436,10 @@ trait HttpClientTrait
$url['path'] = '/'; $url['path'] = '/';
} }
if ('?' === ($url['query'] ?? '')) {
$url['query'] = null;
}
return $url; return $url;
} }

View File

@ -44,6 +44,9 @@ class HttpClientTraitTest extends TestCase
yield ['http://example.com/?a=2&b=b', '.?a=2']; 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' => 3]];
yield ['http://example.com/?a=3&b=b', '.?a=0', ['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' => '']];
} }
/** /**