diff --git a/lib/Cro/HTTP/BodyParsers.pm6 b/lib/Cro/HTTP/BodyParsers.pm6 index 53e11ac..429c2e8 100644 --- a/lib/Cro/HTTP/BodyParsers.pm6 +++ b/lib/Cro/HTTP/BodyParsers.pm6 @@ -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; diff --git a/t/http-request-parser.t b/t/http-request-parser.t index 8a0e305..7b57638 100644 --- a/t/http-request-parser.t +++ b/t/http-request-parser.t @@ -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