Skip to content

Commit ffc94ba

Browse files
author
Daniel Kozák
committed
[HttpClient] Fix #50670 - HttpClient parseUrl is broken and not RFC compliant
1 parent 124311a commit ffc94ba

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/Symfony/Component/HttpClient/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

src/Symfony/Component/HttpClient/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy