Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5904

Show
Ignore:
Timestamp:
01/12/07 09:10:58 (2 years ago)
Author:
bitsweat
Message:

Fix parsing of array[] CGI parameters so extra empty values aren't included. Closes #6252.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r5896 r5904  
    11*SVN* 
     2 
     3* Fix parsing of array[] CGI parameters so extra empty values aren't included.  #6252 [Nicholas Seckar, aiwilliams, brentrowland] 
    24 
    35* link_to_unless_current works with full URLs as well as paths.  #6891 [Jarkko Laine, manfred, idrifter] 
  • trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb

    r5473 r5904  
    2424      parser = FormEncodedPairParser.new 
    2525 
    26       finished = false 
    27       until finished 
    28         finished = true 
     26      params = params.dup 
     27      until params.empty? 
    2928        for key, value in params 
    30           next if key.blank? 
    31           if !key.include?('[') 
     29          if key.blank? 
     30            params.delete key 
     31          elsif !key.include?('[') 
    3232            # much faster to test for the most common case first (GET) 
    3333            # and avoid the call to build_deep_hash 
    3434            parser.result[key] = get_typed_value(value[0]) 
     35            params.delete key 
    3536          elsif value.is_a?(Array) 
    3637            parser.parse(key, get_typed_value(value.shift)) 
    37             finished = false unless value.empty? 
     38            params.delete key if value.empty? 
    3839          else 
    3940            raise TypeError, "Expected array, found #{value.inspect}" 
  • trunk/actionpack/test/controller/cgi_test.rb

    r5473 r5904  
    426426    assert_equal ["yes"], alt_cookies["is_admin"] 
    427427  end 
     428   
     429  def test_unbalanced_query_string_with_array 
     430   assert_equal( 
     431     {'location' => ["1", "2"], 'age_group' => ["2"]}, 
     432  CGIMethods.parse_query_parameters("location[]=1&location[]=2&age_group[]=2") 
     433   ) 
     434   assert_equal( 
     435     {'location' => ["1", "2"], 'age_group' => ["2"]}, 
     436     CGIMethods.parse_request_parameters({'location[]' => ["1", "2"], 
     437  'age_group[]' => ["2"]}) 
     438   ) 
     439  end 
    428440end