Skip to content

Commit 23be6a6

Browse files
fix: Fix the Url::percentRecodeQuery method
URLs can have several parameters with the same name (e.g. `?foo=bar&foo=baz`), which are accessible in an array (see `Url::parseQuery()`). However, the `percentRecodeQuery` method wasn't aware of this possibility and was executing the `fullPercentDecode()` method directly on the array instead of each part of the array.
1 parent 9cd437a commit 23be6a6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/SpiderBits/src/Url.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ private static function percentRecodeQuery($query)
276276
$parameters = self::parseQuery($query);
277277
foreach ($parameters as $name => $value) {
278278
$name = rawurlencode(self::fullPercentDecode($name));
279-
if ($value !== null) {
279+
if (is_array($value)) {
280+
$value = array_map(function ($partial_value) {
281+
return rawurlencode(self::fullPercentDecode($partial_value));
282+
}, $value);
283+
} elseif ($value !== null) {
280284
$value = rawurlencode(self::fullPercentDecode($value));
281285
}
282286
$decoded_parameters[$name] = $value;

tests/lib/SpiderBits/UrlTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function sanitizeProvider()
118118
['https://example.com/?url=http%3A%2F%2Fexample.fr%2F%3Ffoo%3Dbar&spam=egg', 'https://example.com/?url=http%3A%2F%2Fexample.fr%2F%3Ffoo%3Dbar&spam=egg'], // phpcs:ignore Generic.Files.LineLength.TooLong
119119
['https://example.com/?foo?=bar', 'https://example.com/?foo%3F=bar'],
120120
['https://example.com/?foo%26=bar&spam=egg', 'https://example.com/?foo%26=bar&spam=egg'],
121+
['https://example.com/?foo=bar?&foo=baz?', 'https://example.com/?foo=bar%3F&foo=baz%3F'],
121122
["https://domén-with-accent.com?query=with-àccent", 'https://xn--domn-with-accent-dqb.com/?query=with-%C3%A0ccent'], // phpcs:ignore Generic.Files.LineLength.TooLong
122123
["https://host.com?query=with-%C3%A0ccent", 'https://host.com/?query=with-%C3%A0ccent'],
123124
["https://host.com?utm_source=gazette%252B-%252Babonn%25C3%25A9s", 'https://host.com/?utm_source=gazette%2B-%2Babonn%C3%A9s'], // phpcs:ignore Generic.Files.LineLength.TooLong

0 commit comments

Comments
 (0)