FU::Util::query_decode(): Properly handle empty "&"-parts

This commit is contained in:
Yorhel 2025-04-25 17:07:56 +02:00
parent 0cd947c545
commit 5f8809d052
2 changed files with 3 additions and 0 deletions

View file

@ -41,6 +41,7 @@ sub uri_unescape :prototype($) ($s) {
sub query_decode :prototype($) ($s) { sub query_decode :prototype($) ($s) {
my %o; my %o;
for (split /&/, $s//'') { for (split /&/, $s//'') {
next if !length;
my($k,$v) = map uri_unescape($_), split /=/, $_, 2; my($k,$v) = map uri_unescape($_), split /=/, $_, 2;
$v //= builtin::true; $v //= builtin::true;
if (ref $o{$k}) { push $o{$k}->@*, $v } if (ref $o{$k}) { push $o{$k}->@*, $v }

View file

@ -10,6 +10,8 @@ is_deeply
ok !eval { query_decode('%10'); 1 }; ok !eval { query_decode('%10'); 1 };
like $@, qr/Invalid control character/; like $@, qr/Invalid control character/;
is_deeply query_decode('&&&a=b'), { a => 'b' };
is query_encode is query_encode
{ a => builtin::true, b => undef, c => builtin::false, d => 'string', e => "&=\xfe" }, { a => builtin::true, b => undef, c => builtin::false, d => 'string', e => "&=\xfe" },
'a&d=string&e=%26%3d%c3%be'; 'a&d=string&e=%26%3d%c3%be';