Skip to content

Commit 0dd5c06

Browse files
bug #50671 [HttpClient] Fix encoding some characters in query strings (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
2 parents 3d60434 + a5cade7 commit 0dd5c06

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

HttpClientTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ private static function parseUrl(string $url, array $query = [], array $allowedS
547547
}
548548

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

553553
return [
@@ -634,11 +634,7 @@ private static function mergeQueryString(?string $queryString, array $queryArray
634634
'%3B' => ';',
635635
'%40' => '@',
636636
'%5B' => '[',
637-
'%5C' => '\\',
638637
'%5D' => ']',
639-
'%5E' => '^',
640-
'%60' => '`',
641-
'%7C' => '|',
642638
]);
643639
}
644640

Tests/HttpClientTraitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ public static function provideParseUrl(): iterable
155155
yield [['http:', '//example.com', null, null, null], 'http://Example.coM:80'];
156156
yield [['https:', '//xn--dj-kia8a.example.com:8000', '/', null, null], 'https://DÉjà.Example.com:8000/'];
157157
yield [[null, null, '/f%20o.o', '?a=b', '#c'], '/f o%2Eo?a=b#c'];
158+
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'];
158159
yield [[null, '//a:b@foo', '/bar', null, null], '//a:b@foo/bar'];
159160
yield [[null, '//a:b@foo', '/b{}', null, null], '//a:b@foo/b{}'];
160161
yield [['http:', null, null, null, null], 'http:'];
161162
yield [['http:', null, 'bar', null, null], 'http:bar'];
162163
yield [[null, null, 'bar', '?a=1&c=c', null], 'bar?a=a&b=b', ['b' => null, 'c' => 'c', 'a' => 1]];
163-
yield [[null, null, 'bar', '?a=b+c&b=b-._~!$%26/%27()[]*%2B%2C;%3D:@%25\\^`%7B|%7D', null], 'bar?a=b+c', ['b' => 'b-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
164+
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-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
164165
yield [[null, null, 'bar', '?a=b%2B%20c', null], 'bar?a=b+c', ['a' => 'b+ c']];
165166
yield [[null, null, 'bar', '?a[b]=c', null], 'bar', ['a' => ['b' => 'c']]];
166167
yield [[null, null, 'bar', '?a[b[c]=d', null], 'bar?a[b[c]=d', []];

0 commit comments

Comments
 (0)