Skip to content

Commit

Permalink
Fix broken query params (#55)
Browse files Browse the repository at this point in the history
* fix query params

* cleanup param name regex
  • Loading branch information
rawleyfowler authored May 12, 2023
1 parent 2b82a87 commit 1c4c16c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
"Test::Util::ServerPort",
"Cro::HTTP::Client"
],
"version": "2.1.3"
"version": "2.1.4"
}
4 changes: 2 additions & 2 deletions lib/Humming-Bird/Core.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand Down
27 changes: 27 additions & 0 deletions t/11-advanced-query.rakutest
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 1c4c16c

Please sign in to comment.