summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-07-21 08:22:51 -0700
committerJeremy Evans <code@jeremyevans.net>2022-01-24 20:49:18 -0800
commitf1583d47f695a1799fb568bb57f2c3687d2fd40c (patch)
tree187865312c6d30130585d5a330d3644b38c0f7b0 /test
parent60669aa2deacef3c8ee7fab6ba87491e9a24af9e (diff)
downloadrack-f1583d47f695a1799fb568bb57f2c3687d2fd40c.tar.gz
Make query string parsing conform to URL spec
The URL spec section 5.1.3.3 specifies that if = is not present in the byte sequence, it should be treated as if the byte sequence is the name of the tuple and the value is the empty string. This affects all parameters without =, not just arrays: ```ruby Rack::Utils.parse_nested_query("foo[bar]&baz[]&quux") {"foo"=>{"bar"=>nil}, "baz"=>[nil], "quux"=>nil} # Before {"foo"=>{"bar"=>""}, "baz"=>[""], "quux"=>""} # After ``` Fixes #1696
Diffstat (limited to 'test')
-rw-r--r--test/spec_utils.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/test/spec_utils.rb b/test/spec_utils.rb
index 6aa0c17e..f753f85b 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -135,7 +135,7 @@ describe Rack::Utils do
it "parse nested query strings correctly" do
Rack::Utils.parse_nested_query("foo").
- must_equal "foo" => nil
+ must_equal "foo" => ""
Rack::Utils.parse_nested_query("foo=").
must_equal "foo" => ""
Rack::Utils.parse_nested_query("foo=bar").
@@ -152,7 +152,7 @@ describe Rack::Utils do
Rack::Utils.parse_nested_query("&foo=1&&bar=2").
must_equal "foo" => "1", "bar" => "2"
Rack::Utils.parse_nested_query("foo&bar=").
- must_equal "foo" => nil, "bar" => ""
+ must_equal "foo" => "", "bar" => ""
Rack::Utils.parse_nested_query("foo=bar&baz=").
must_equal "foo" => "bar", "baz" => ""
Rack::Utils.parse_nested_query("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F").
@@ -162,19 +162,19 @@ describe Rack::Utils do
must_equal "pid=1234" => "1023", "a" => "b"
Rack::Utils.parse_nested_query("foo[]").
- must_equal "foo" => [nil]
+ must_equal "foo" => [""]
Rack::Utils.parse_nested_query("foo[]=").
must_equal "foo" => [""]
Rack::Utils.parse_nested_query("foo[]=bar").
must_equal "foo" => ["bar"]
Rack::Utils.parse_nested_query("foo[]=bar&foo").
- must_equal "foo" => nil
+ must_equal "foo" => ""
Rack::Utils.parse_nested_query("foo[]=bar&foo[").
- must_equal "foo" => ["bar"], "foo[" => nil
+ must_equal "foo" => ["bar"], "foo[" => ""
Rack::Utils.parse_nested_query("foo[]=bar&foo[=baz").
must_equal "foo" => ["bar"], "foo[" => "baz"
Rack::Utils.parse_nested_query("foo[]=bar&foo[]").
- must_equal "foo" => ["bar", nil]
+ must_equal "foo" => ["bar", ""]
Rack::Utils.parse_nested_query("foo[]=bar&foo[]=").
must_equal "foo" => ["bar", ""]
@@ -185,6 +185,8 @@ describe Rack::Utils do
Rack::Utils.parse_nested_query("foo[]=bar&baz[]=1&baz[]=2&baz[]=3").
must_equal "foo" => ["bar"], "baz" => ["1", "2", "3"]
+ Rack::Utils.parse_nested_query("x[y][z]").
+ must_equal "x" => { "y" => { "z" => "" } }
Rack::Utils.parse_nested_query("x[y][z]=1").
must_equal "x" => { "y" => { "z" => "1" } }
Rack::Utils.parse_nested_query("x[y][z][]=1").
@@ -338,7 +340,7 @@ describe Rack::Utils do
end
it 'performs the inverse function of #parse_nested_query' do
- [{ "foo" => nil, "bar" => "" },
+ [{ "bar" => "" },
{ "foo" => "bar", "baz" => "" },
{ "foo" => ["1", "2"] },
{ "foo" => "bar", "baz" => ["1", "2", "3"] },