Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7758591

Browse files
[HttpClient] Fix over-encoding of URL parts to match browser's behavior
1 parent daec724 commit 7758591

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 6 additions & 1 deletion
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 [
@@ -621,6 +621,11 @@ private static function mergeQueryString(?string $queryString, array $queryArray
621621
$queryArray = [];
622622

623623
if ($queryString) {
624+
if (str_contains($queryString, '%')) {
625+
// https://tools.ietf.org/html/rfc3986#section-2.3
626+
$queryString = preg_replace_callback('/%(?:2[148-F]|3[0-B]|40|[46][1-9A-F]|5F|60|[57][0-E])++/i', function ($m) { return rawurldecode($m[0]); }, $queryString);
627+
}
628+
624629
foreach (explode('&', $queryString) as $v) {
625630
$queryArray[rawurldecode(explode('=', $v, 2)[0])] = $v;
626631
}

src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ public function provideParseUrl(): iterable
157157
yield [['http:', null, null, null, null], 'http:'];
158158
yield [['http:', null, 'bar', null, null], 'http:bar'];
159159
yield [[null, null, 'bar', '?a=1&c=c', null], 'bar?a=a&b=b', ['b' => null, 'c' => 'c', 'a' => 1]];
160-
yield [[null, null, 'bar', '?a=b+c&b=b', null], 'bar?a=b+c', ['b' => 'b']];
161-
yield [[null, null, 'bar', '?a=b%2B%20c', null], 'bar?a=b+c', ['a' => 'b+ c']];
162-
yield [[null, null, 'bar', '?a%5Bb%5D=c', null], 'bar', ['a' => ['b' => 'c']]];
163-
yield [[null, null, 'bar', '?a%5Bb%5Bc%5D=d', null], 'bar?a[b[c]=d', []];
164-
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]];
165-
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' => '']];
160+
yield [[null, null, 'bar', '?a=b+c&b=b-._~!$%26/%27()[]*+,;%3D:@%25\\^`{|}', null], 'bar?a=b+c', ['b' => 'b-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
161+
yield [[null, null, 'bar', '?a=b+%20c', null], 'bar?a=b+c', ['a' => 'b+ c']];
162+
yield [[null, null, 'bar', '?a[b]=c', null], 'bar', ['a' => ['b' => 'c']]];
163+
yield [[null, null, 'bar', '?a[b[c]=d', null], 'bar?a[b[c]=d', []];
164+
yield [[null, null, 'bar', '?a[b][c]=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]];
165+
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' => '']];
166166
// IDNA 2008 compliance
167167
yield [['https:', '//xn--fuball-cta.test', null, null, null], 'https://fußball.test'];
168168
}

src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function unsupportedMessagesProvider(): iterable
5252
*/
5353
public function testTestMode(int $expected, bool $testMode)
5454
{
55-
$message = new SmsMessage('+37012345678', 'Hello World!');
55+
$message = new SmsMessage('+37012345678', 'Hello World');
5656

5757
$response = $this->createMock(ResponseInterface::class);
5858
$response->expects($this->atLeast(1))

0 commit comments

Comments
 (0)