Skip to content
Browse files

Handle parameter names with brackets properly

  • Loading branch information...
1 parent 4c46b93 commit 6edb396d792851fccb837f504e8ea3abfe208e00 @ttdonovan ttdonovan committed with brynary Apr 28, 2010
Showing with 14 additions and 1 deletion.
  1. +6 −0 History.txt
  2. +4 −1 lib/rack/test/utils.rb
  3. +4 −0 spec/rack/test/utils_spec.rb
View
6 History.txt
@@ -1,3 +1,9 @@
+== Git
+
+* Bug fixes
+
+ * Handle parameter names with brackets properly (Tanner Donovan)
+
== 0.5.3 / 2009-11-27
* Bug fixes
View
5 lib/rack/test/utils.rb
@@ -8,7 +8,10 @@ def build_nested_query(value, prefix = nil)
case value
when Array
value.map do |v|
- build_nested_query(v, "#{prefix}[]")
+ unless unescape(prefix) =~ /\[\]$/
+ prefix = "#{prefix}[]"
+ end
+ build_nested_query(v, "#{prefix}")
end.join("&")
when Hash
value.map do |k, v|
View
4 spec/rack/test/utils_spec.rb
@@ -33,6 +33,10 @@
build_nested_query(:a => [1, 2]).should == "a[]=1&a[]=2"
end
+ it "converts arrays with brackets '[]' in the name" do
+ build_nested_query("a[]" => [1, 2]).should == "a%5B%5D=1&a%5B%5D=2"
+ end
+
it "converts nested hashes" do
build_nested_query(:a => { :b => 1 }).should == "a[b]=1"
end

0 comments on commit 6edb396

Please sign in to comment.
Something went wrong with that request. Please try again.