From a1159fa72210fb7e68908ea5d184d087e84696f0 Mon Sep 17 00:00:00 2001 From: Anthony Parsons Date: Sat, 27 Oct 2012 14:12:30 +0100 Subject: [PATCH] Fixes to Request.params --- lib/Bailador/Request.pm | 4 ++-- t/05-post-content.t | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 t/05-post-content.t diff --git a/lib/Bailador/Request.pm b/lib/Bailador/Request.pm index 3f3525c..b16bfac 100644 --- a/lib/Bailador/Request.pm +++ b/lib/Bailador/Request.pm @@ -5,8 +5,8 @@ class Bailador::Request { method params { my %ret; - for $.env.split('&') -> $p { - my $pair = $p.split('='); + for $.env.decode.split('&') -> $p { + my $pair = $p.split('=', 2); %ret{$pair[0]} = uri_unescape $pair[1]; } return %ret; diff --git a/t/05-post-content.t b/t/05-post-content.t new file mode 100644 index 0000000..584f07c --- /dev/null +++ b/t/05-post-content.t @@ -0,0 +1,16 @@ +use Test; +use Bailador; +use Bailador::Test; + +plan 3; + +post '/foo' => sub { request.env.decode }; + +my $data = 'hello=world&a=1;b=2'; +my $req = Bailador::Request.new_for_request('POST', '/foo'); + $req.env = $postdata.encode('utf-8'); +my $resp = Bailador::dispatch_request($req); + +lives_ok { eager $req.params }, 'Request data parses without dying'; +is ~$resp.content, $data, 'POST data string roundtrips correctly'; +is $req.params, '1;b=2', 'application/x-www-form-urlencoded POST data should only split on &';