Skip to content

Commit

Permalink
[HttpClient] Fix encoding some characters in query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kozák authored and nicolas-grekas committed Jun 21, 2023
1 parent 9e89ac4 commit a5cade7
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 a5cade7

Please sign in to comment.