Skip to content

Commit

Permalink
Fix x-www-form-urlencoded with missing values
Browse files Browse the repository at this point in the history
These produced an exception during parsing.
  • Loading branch information
jnthn committed Jan 22, 2024
1 parent 2d1d9b4 commit 40b2f6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cro/HTTP/BodyParsers.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Cro::HTTP::BodyParser::WWWFormUrlEncoded does Cro::BodyParser {
my $encoding = self.default-encoding;
for $payload.split('&') -> Str $string {
my Str $string-sp = $string.subst('+', ' ', :g);
my int $eq-idx = $string-sp.index('=');
my int $eq-idx = $string-sp.index('=') // -1;
my Str $name = $eq-idx >= 0
?? $string-sp.substr(0, $eq-idx)
!! $string-sp;
Expand Down
13 changes: 13 additions & 0 deletions t/http-request-parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,19 @@ parses 'A _charset_ in application/x-www-form-urlencoded overrides configured de
'Values were decoded as utf-8, not latin-1 default, due to _charset_';
};

parses 'No errors on keys with empty value or missing value',
q:to/REQUEST/.chop,
POST /bar HTTP/1.1
Content-type: application/x-www-form-urlencoded; charset=UTF-8
Content-length: 4
a=&b
REQUEST
tests => {
my $body = .body.result;
is-deeply $body.list, (a => '', b => '');
};

parses 'Simple multipart/form-data',
q:to/REQUEST/, :body-crlf,
POST /bar HTTP/1.1
Expand Down

0 comments on commit 40b2f6b

Please sign in to comment.