Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query without '=' is form too #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/URI/_query.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 10 additions & 2 deletions t/query.t
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -31,8 +31,9 @@ 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;
ok !@q;
is join(":", @q ), ' + = [ ]:';

$u->query(" +?=#");
is $u, "?%20+?=%23";
Expand Down Expand Up @@ -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:';