From: Matt S Trout Date: Fri, 14 Aug 2015 15:01:49 +0000 (+0000) Subject: handle empty query parameters X-Git-Tag: v0.031~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6f0e017fa30d4f1414f883acdc4d7a824a32c93b;p=catagits%2FWeb-Simple.git handle empty query parameters --- diff --git a/Changes b/Changes index 30b28aa..b1fc756 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Web-Simple + - handle empty query parameters - produce a sensible error for (GET => undef) on 5.8 0.030 - 2014-08-07 diff --git a/lib/Web/Dispatch/ParamParser.pm b/lib/Web/Dispatch/ParamParser.pm index 3caf160..e55c312 100644 --- a/lib/Web/Dispatch/ParamParser.pm +++ b/lib/Web/Dispatch/ParamParser.pm @@ -104,7 +104,7 @@ sub get_unpacked_uploads_from { (my $params = $_[0]) =~ s/\+/ /g; my ($name, $value); foreach my $pair (split(/[&;](?:\s+)?/, $params)) { - next unless (($name, $value) = split(/=/, $pair, 2)) == 2; + $value = 1 unless (($name, $value) = split(/=/, $pair, 2)) == 2; s/$DECODE/$hex_chr{$1}/gs for ($name, $value); $_ = decode_utf8 $_ for ($name, $value); diff --git a/lib/Web/Simple.pm b/lib/Web/Simple.pm index 8685d39..134c7ae 100644 --- a/lib/Web/Simple.pm +++ b/lib/Web/Simple.pm @@ -526,7 +526,9 @@ The param spec is elements of one of the following forms: separated by the C<&> character. The arguments added to the request are one per non-C<:>/C<*> parameter (scalar for normal, arrayref for multiple), -plus if any C<:>/C<*> specs exist a hashref containing those values. +plus if any C<:>/C<*> specs exist a hashref containing those values. If a +parameter has no value, i.e. appears as '?foo&', a value of 1 will be +captured. Please note that if you specify a multiple type parameter match, you are ensured of getting an arrayref for the value, EVEN if the current incoming diff --git a/t/param_parser.t b/t/param_parser.t index 7a35bac..d539b1d 100644 --- a/t/param_parser.t +++ b/t/param_parser.t @@ -5,7 +5,7 @@ use Test::More qw(no_plan); use Web::Dispatch::ParamParser; -my $param_sample = 'foo=bar&baz=quux&foo=%2F'; +my $param_sample = 'foo=bar&baz=quux&foo=%2F&xyzzy'; my $unpacked = { baz => [ "quux" @@ -13,11 +13,14 @@ my $unpacked = { foo => [ "bar", "/" + ], + xyzzy => [ + 1 ] }; is_deeply( - Web::Dispatch::ParamParser::_unpack_params('foo=bar&baz=quux&foo=%2F'), + Web::Dispatch::ParamParser::_unpack_params('foo=bar&baz=quux&foo=%2F&xyzzy'), $unpacked, 'Simple unpack ok' ); @@ -36,7 +39,7 @@ is_deeply( 'Unpack cached ok' ); -sub FakeBody::param { { baz => "quux", foo => [ "bar", "/" ] } } +sub FakeBody::param { { baz => "quux", foo => [ "bar", "/" ], xyzzy => [ 1 ] } } my $body_env = { CONTENT_TYPE => "multipart/form-data",