diff --git a/META6.json b/META6.json index 78748d1..b65ed7e 100644 --- a/META6.json +++ b/META6.json @@ -42,5 +42,5 @@ "Test::Util::ServerPort", "Cro::HTTP::Client" ], - "version": "2.1.3" + "version": "2.1.4" } diff --git a/lib/Humming-Bird/Core.rakumod b/lib/Humming-Bird/Core.rakumod index 060ff53..cc7a397 100644 --- a/lib/Humming-Bird/Core.rakumod +++ b/lib/Humming-Bird/Core.rakumod @@ -9,7 +9,7 @@ use Humming-Bird::HTTPServer; unit module Humming-Bird::Core; -our constant $VERSION = '2.1.3'; +our constant $VERSION = '2.1.4'; # Mime type parser from MIME::Types my constant $mime = MIME::Types.new; @@ -153,7 +153,7 @@ class Request is HTTPAction is export { # Find query params my %query; - if uri_decode_component(@lines[0]) ~~ m:g /<[a..z A..Z 0..9]>+"="<[a..z A..Z 0..9]>+/ { + if uri_decode_component($path) ~~ m:g /\w+"="(<-[&]>+)/ { %query = Map.new($<>.map({ .split('=', 2) }).flat); $path = $path.split('?', 2)[0]; } diff --git a/t/11-advanced-query.rakutest b/t/11-advanced-query.rakutest new file mode 100644 index 0000000..a26c659 --- /dev/null +++ b/t/11-advanced-query.rakutest @@ -0,0 +1,27 @@ +use v6; +use strict; +use lib 'lib'; + +use Test; +use Humming-Bird::Core; + +plan 9; + +my $simple_raw_request = "GET /?foo=bar%40baz HTTP/1.1\r\nHost: bob.com\r\n"; +my $simple_request = Request.decode($simple_raw_request); + +ok $simple_request.method === GET, 'Is method OK?'; +is $simple_request.version, 'HTTP/1.1', 'Is version OK?'; +is $simple_request.path, '/', 'Is path OK?'; +is $simple_request.query('foo'), 'bar@baz', 'Is query param correct?'; + +my $advanced_raw_request = "GET /?foo=bar%40baz&j=123%40abc HTTP/1.1\r\nHost: bob.com\r\n"; +my $advanced_request = Request.decode: $advanced_raw_request; + +ok $advanced_request.method === GET, 'Is method OK?'; +is $advanced_request.version, 'HTTP/1.1', 'Is version OK?'; +is $advanced_request.path, '/', 'Is path OK?'; +is $advanced_request.query('foo'), 'bar@baz', 'Is first of query params correct?'; +is $advanced_request.query('j'), '123@abc', 'Is second of query params correct?'; + +done-testing;