Skip to content
Closed
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
3 changes: 3 additions & 0 deletions src/State/Tests/Util/RequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static function parseRequestParamsProvider(): array

// urlencoded [] (square brackets) in query string.
['a%5B1%5D=%2525', ['a' => ['1' => '%25']]],

// malformed query string with unclosed bracket and multibyte characters
['y%5B%C2%9D=', ['79_'."\xC2\x9D" => '']],
];
}
}
13 changes: 12 additions & 1 deletion src/State/Util/RequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ public static function parseRequestParams(string $source): array
// parse_str urldecodes both keys and values in resulting array.
parse_str($source, $params);

return array_combine(array_map('hex2bin', array_keys($params)), $params);
$keys = array_map(
static function (string $key): string {
if (0 !== \strlen($key) % 2 || \strlen($key) !== strspn($key, '0123456789abcdef')) {
return $key;
}

return hex2bin($key);
},
array_keys($params),
);

return array_combine($keys, $params);
}

/**
Expand Down
Loading