Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge [5904] from trunk. References #6252.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5906 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit dd605e937fcbe9b764fda8e0245946d0ce177845 1 parent d12bcda
@jeremy jeremy authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fix parsing of array[] CGI parameters so extra empty values aren't included. #6252 [Nicholas Seckar, aiwilliams, brentrowland]
+
* link_to_unless_current works with full URLs as well as paths. #6891 [Jarkko Laine, manfred, idrifter]
* Fix HTML::Node to output double quotes instead of single quotes. Closes #6845 [mitreandy]
View
13 actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
@@ -23,18 +23,19 @@ def parse_query_parameters(query_string)
def parse_request_parameters(params)
parser = FormEncodedPairParser.new
- finished = false
- until finished
- finished = true
+ params = params.dup
+ until params.empty?
for key, value in params
- next if key.blank?
- if !key.include?('[')
+ if key.blank?
+ params.delete key
+ elsif !key.include?('[')
# much faster to test for the most common case first (GET)
# and avoid the call to build_deep_hash
parser.result[key] = get_typed_value(value[0])
+ params.delete key
elsif value.is_a?(Array)
parser.parse(key, get_typed_value(value.shift))
- finished = false unless value.empty?
+ params.delete key if value.empty?
else
raise TypeError, "Expected array, found #{value.inspect}"
end
View
12 actionpack/test/controller/cgi_test.rb
@@ -425,4 +425,16 @@ def test_cookie_syntax_resilience
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], alt_cookies["_session_id"]
assert_equal ["yes"], alt_cookies["is_admin"]
end
+
+ def test_unbalanced_query_string_with_array
+ assert_equal(
+ {'location' => ["1", "2"], 'age_group' => ["2"]},
+ CGIMethods.parse_query_parameters("location[]=1&location[]=2&age_group[]=2")
+ )
+ assert_equal(
+ {'location' => ["1", "2"], 'age_group' => ["2"]},
+ CGIMethods.parse_request_parameters({'location[]' => ["1", "2"],
+ 'age_group[]' => ["2"]})
+ )
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.