Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Fix over-encoding of URL parts to match browser's behavior #49299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion 27 src/Symfony/Component/HttpClient/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 @@ -621,6 +621,31 @@ private static function mergeQueryString(?string $queryString, array $queryArray
$queryArray = [];

if ($queryString) {
if (str_contains($queryString, '%')) {
// https://tools.ietf.org/html/rfc3986#section-2.3 + some chars not encoded by browsers
$queryString = strtr($queryString, [
'%21' => '!',
'%24' => '$',
'%28' => '(',
'%29' => ')',
'%2A' => '*',
'%2B' => '+',
'%2C' => ',',
'%2F' => '/',
'%3A' => ':',
'%3B' => ';',
'%40' => '@',
'%5B' => '[',
'%5C' => '\\',
'%5D' => ']',
'%5E' => '^',
'%60' => '`',
'%7B' => '{',
'%7C' => '|',
'%7D' => '}',
]);
}

foreach (explode('&', $queryString) as $v) {
$queryArray[rawurldecode(explode('=', $v, 2)[0])] = $v;
}
Expand Down
12 changes: 6 additions & 6 deletions 12 src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ public function provideParseUrl(): iterable
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', 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%5Bb%5D=c', null], 'bar', ['a' => ['b' => 'c']]];
yield [[null, null, 'bar', '?a%5Bb%5Bc%5D=d', null], 'bar?a[b[c]=d', []];
yield [[null, null, 'bar', '?a%5Bb%5D%5Bc%5D=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]];
yield [[null, null, 'bar', '?a=b&a%5Bb%20c%5D=d&e%3Df=%E2%9C%93', null], 'bar?a=b', ['a' => ['b c' => 'd'], 'e=f' => '✓']];
yield [[null, null, 'bar', '?a=b+c&b=b-._~!$%26/%27()[]*+,;%3D:@%25\\^`{|}', null], 'bar?a=b+c', ['b' => 'b-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
yield [[null, null, 'bar', '?a=b+%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', []];
yield [[null, null, 'bar', '?a[b][c]=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]];
yield [[null, null, 'bar', '?a=b&a[b%20c]=d&e%3Df=%E2%9C%93', null], 'bar?a=b', ['a' => ['b c' => 'd'], 'e=f' => '✓']];
// IDNA 2008 compliance
yield [['https:', '//xn--fuball-cta.test', null, null, null], 'https://fußball.test'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function unsupportedMessagesProvider(): iterable
*/
public function testTestMode(int $expected, bool $testMode)
{
$message = new SmsMessage('+37012345678', 'Hello World!');
$message = new SmsMessage('0037012345678', 'Hello World');

$response = $this->createMock(ResponseInterface::class);
$response->expects($this->atLeast(1))
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.