Skip to content

Commit

Permalink
bug #50671 [HttpClient] Fix encoding some characters in query strings…
Browse files Browse the repository at this point in the history
… (Daniel Kozák)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[HttpClient] Fix encoding some characters in query strings

| Q             | A
| ------------- | ---
| Branch?       | 5.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #50670 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix.
This will help reviewers and should be a good start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the latest branch.
 - For new features, provide some code snippets to help understand usage.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
 - Never break backward compatibility (see https://symfony.com/bc).
-->

Commits
-------

cb26c19c48 [HttpClient] Fix encoding some characters in query strings
  • Loading branch information
nicolas-grekas committed Jun 21, 2023
2 parents 3d60434 + a5cade7 commit 0dd5c06
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 1 addition & 5 deletions HttpClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private static function parseUrl(string $url, array $query = [], array $allowedS
}

// https://tools.ietf.org/html/rfc3986#section-3.3
$parts[$part] = preg_replace_callback("#[^-A-Za-z0-9._~!$&/'()[\]*+,;=:@\\\\^`{|}%]++#", function ($m) { return rawurlencode($m[0]); }, $parts[$part]);
$parts[$part] = preg_replace_callback("#[^-A-Za-z0-9._~!$&/'()[\]*+,;=:@{}%]++#", function ($m) { return rawurlencode($m[0]); }, $parts[$part]);
}

return [
Expand Down Expand Up @@ -634,11 +634,7 @@ private static function mergeQueryString(?string $queryString, array $queryArray
'%3B' => ';',
'%40' => '@',
'%5B' => '[',
'%5C' => '\\',
'%5D' => ']',
'%5E' => '^',
'%60' => '`',
'%7C' => '|',
]);
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/HttpClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ public static function provideParseUrl(): iterable
yield [['http:', '//example.com', null, null, null], 'http://Example.coM:80'];
yield [['https:', '//xn--dj-kia8a.example.com:8000', '/', null, null], 'https://DÉjà.Example.com:8000/'];
yield [[null, null, '/f%20o.o', '?a=b', '#c'], '/f o%2Eo?a=b#c'];
yield [[null, null, '/custom%7C2010-01-01%2000:00:00%7C2023-06-15%2005:50:35', '?a=b', '#c'], '/custom|2010-01-01 00:00:00|2023-06-15 05:50:35?a=b#c'];
yield [[null, '//a:b@foo', '/bar', null, null], '//a:b@foo/bar'];
yield [[null, '//a:b@foo', '/b{}', null, null], '//a:b@foo/b{}'];
yield [['http:', null, null, null, null], 'http:'];
yield [['http:', null, 'bar', null, null], 'http:bar'];
yield [[null, null, 'bar', '?a=1&c=c', null], 'bar?a=a&b=b', ['b' => null, 'c' => 'c', 'a' => 1]];
yield [[null, null, 'bar', '?a=b+c&b=b-._~!$%26/%27()[]*%2B%2C;%3D:@%25\\^`%7B|%7D', null], 'bar?a=b+c', ['b' => 'b-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
yield [[null, null, 'bar', '?a=b+c&b=b-._~!$%26/%27()[]*%2B%2C;%3D:@%25%5C%5E%60%7B%7C%7D', null], 'bar?a=b+c', ['b' => 'b-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
yield [[null, null, 'bar', '?a=b%2B%20c', null], 'bar?a=b+c', ['a' => 'b+ c']];
yield [[null, null, 'bar', '?a[b]=c', null], 'bar', ['a' => ['b' => 'c']]];
yield [[null, null, 'bar', '?a[b[c]=d', null], 'bar?a[b[c]=d', []];
Expand Down

0 comments on commit 0dd5c06

Please sign in to comment.