Skip to content
Browse files

Failing tests for to_param/to_query not escaping "[]"

  • Loading branch information...
1 parent 49e943c commit 1ee9b40b18a0bed5bb10a0785f7e2730bac983f6 @josh josh committed Dec 2, 2009
View
2 activesupport/lib/active_support/core_ext/object/to_param.rb
@@ -38,7 +38,7 @@ class Hash
# ==== Examples
# { :name => 'David', :nationality => 'Danish' }.to_query # => "name=David&nationality=Danish"
#
- # { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
+ # { :name => 'David', :nationality => 'Danish' }.to_query('user') # => "user[name]=David&user[nationality]=Danish"
def to_param(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
View
2 activesupport/lib/active_support/core_ext/object/to_query.rb
@@ -15,7 +15,7 @@ class Array
# Converts an array into a string suitable for use as a URL query string,
# using the given +key+ as the param name.
#
- # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
+ # ['Rails', 'coding'].to_query('hobbies') # => "hobbies[]=Rails&hobbies[]=coding"
def to_query(key)
prefix = "#{key}[]"
collect { |value| value.to_query(prefix) }.join '&'
View
8 activesupport/test/core_ext/object/to_query_test.rb
@@ -17,22 +17,22 @@ def empty.to_param; nil end
end
def test_nested_conversion
- assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas',
+ assert_query_equal 'person[login]=seckar&person[name]=Nicholas',
:person => {:name => 'Nicholas', :login => 'seckar'}
end
def test_multiple_nested
- assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
+ assert_query_equal 'account[person][id]=20&person[id]=10',
:person => {:id => 10}, :account => {:person => {:id => 20}}
end
def test_array_values
- assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
+ assert_query_equal 'person[id][]=10&person[id][]=20',
:person => {:id => [10, 20]}
end
def test_array_values_are_not_sorted
- assert_query_equal 'person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10',
+ assert_query_equal 'person[id][]=20&person[id][]=10',
:person => {:id => [20, 10]}
end

0 comments on commit 1ee9b40

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