Ticket #2295 - Tolerate consecutive delimiters in query parameters

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2375 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2005-09-27 22:23:37 +00:00
parent 0c23f06129
commit 17d2732b1c
3 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,7 @@
*SVN* *SVN*
* Tolerate consecutive delimiters in query parameters. #2295 [darashi@gmail.com]
* Streamline render process, code cleaning. Closes #2294. [skae] * Streamline render process, code cleaning. Closes #2294. [skae]
* Keep flash after components are rendered. #2291 [Rick Olson, Scott] * Keep flash after components are rendered. #2291 [Rick Olson, Scott]

View File

@ -11,6 +11,9 @@ class CGIMethods #:nodoc:
parsed_params = {} parsed_params = {}
query_string.split(/[&;]/).each { |p| query_string.split(/[&;]/).each { |p|
# Ignore repeated delimiters.
next if p.empty?
k, v = p.split('=',2) k, v = p.split('=',2)
v = nil if (v && v.empty?) v = nil if (v && v.empty?)

View File

@ -14,6 +14,8 @@ class CGITest < Test::Unit::TestCase
"action=update_order&full_name=Lau%20Taarnskov&products=4&products=2&products=3" "action=update_order&full_name=Lau%20Taarnskov&products=4&products=2&products=3"
@query_string_with_many_equal = "action=create_customer&full_name=abc=def=ghi" @query_string_with_many_equal = "action=create_customer&full_name=abc=def=ghi"
@query_string_without_equal = "action" @query_string_without_equal = "action"
@query_string_with_many_ampersands =
"&action=create_customer&&&full_name=David%20Heinemeier%20Hansson"
end end
def test_query_string def test_query_string
@ -66,7 +68,14 @@ class CGITest < Test::Unit::TestCase
CGIMethods.parse_query_parameters(@query_string_without_equal) CGIMethods.parse_query_parameters(@query_string_without_equal)
) )
end end
def test_query_string_with_many_ampersands
assert_equal(
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson"},
CGIMethods.parse_query_parameters(@query_string_with_many_ampersands)
)
end
def test_parse_params def test_parse_params
input = { input = {
"customers[boston][first][name]" => [ "David" ], "customers[boston][first][name]" => [ "David" ],