From 4db6cb8605a020c5d5d5e85e067b33a6a1c14847 Mon Sep 17 00:00:00 2001 From: Konstantin Yakunin Date: Tue, 10 Oct 2017 23:32:52 +0300 Subject: [PATCH 1/2] query without '=' is form too --- lib/URI/_query.pm | 1 - t/query.t | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/URI/_query.pm b/lib/URI/_query.pm index 94cb71b5..f8f19137 100644 --- a/lib/URI/_query.pm +++ b/lib/URI/_query.pm @@ -70,7 +70,6 @@ sub query_form { } } return if !defined($old) || !length($old) || !defined(wantarray); - return unless $old =~ /=/; # not a form map { s/\+/ /g; uri_unescape($_) } map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old); } diff --git a/t/query.t b/t/query.t index 29708141..e9643a6d 100644 --- a/t/query.t +++ b/t/query.t @@ -32,7 +32,7 @@ is $u, "?%20+%2B+%3D+%5B+%5D"; is join(":", @q), " :+:=:[:]"; @q = $u->query_form; -ok !@q; +is join(":", @q ), ' + = [ ]:'; $u->query(" +?=#"); is $u, "?%20+?=%23"; From d230f9db138798d973b367e2d6b6bc2748daa65d Mon Sep 17 00:00:00 2001 From: Konstantin Yakunin Date: Wed, 11 Oct 2017 12:33:07 +0300 Subject: [PATCH 2/2] Add more tests and comment a little bit --- t/query.t | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/t/query.t b/t/query.t index e9643a6d..a1faf8dc 100644 --- a/t/query.t +++ b/t/query.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 23; +use Test::More tests => 25; use URI (); my $u = URI->new("", "http"); @@ -31,6 +31,7 @@ is $u, "?%20+%2B+%3D+%5B+%5D"; @q = $u->query_keywords; is join(":", @q), " :+:=:[:]"; +# If someone set query keywords than same keywords can be treated as form parameter @q = $u->query_form; is join(":", @q ), ' + = [ ]:'; @@ -79,3 +80,10 @@ $u->query_form([]); $u->query_form(a => 1, b => 2); } is $u, "?a=1;b=2"; + +# check if url with single query keyword parsed correctly +my $u1 = URI->new("http://example.com/?foo"); +is $u1->query, 'foo'; + +@q = $u1->query_form; +is join(":", @q), 'foo:';