Ticket #9030: indifferent.diff
| File indifferent.diff, 3.5 kB (added by jdrowell, 1 year ago) |
|---|
-
activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
old new 79 79 when Hash 80 80 value.with_indifferent_access 81 81 when Array 82 value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e } 82 # don't do collect() because we need to be sure the object_id doesn't change 83 value.each_index do |i| 84 value[i] = value[i].with_indifferent_access if value[i].is_a?(Hash) 85 end 86 value 83 87 else 84 88 value 85 89 end … … 91 95 module Hash #:nodoc: 92 96 module IndifferentAccess #:nodoc: 93 97 def with_indifferent_access 98 return self if self.is_a?(HashWithIndifferentAccess) 99 94 100 hash = HashWithIndifferentAccess.new(self) 95 101 hash.default = self.default 96 102 hash -
actionpack/test/controller/request_test.rb
old new 410 410 ) 411 411 end 412 412 413 def test_deep_query_string_lots_of_arrays_and_hashes 414 assert_equal( 415 {"a" => {"b" => [{"c" => {"d" => ["1"]}}, {"c" => {"d" => ["2"]}}, {"c" => {"d" => ["3"]}}]}}, 416 ActionController::AbstractRequest.parse_query_parameters('a[b][][c][d][]=1&a[b][][c][d][]=2&a[b][][c][d][]=3') 417 ) 418 end 419 413 420 def test_query_string_with_nil 414 421 assert_equal( 415 422 { "action" => "create_customer", "full_name" => ''}, -
actionpack/lib/action_controller/request.rb
old new 574 574 575 575 def initialize(pairs = []) 576 576 super('') 577 @result = {} 577 @result = {}.with_indifferent_access 578 578 pairs.each { |key, value| parse(key, value) } 579 579 end 580 580 … … 584 584 # Parse the query string 585 585 def parse(key, value) 586 586 self.string = key 587 @top, @parent = result, nil587 @top, @parent = @result, nil 588 588 589 589 # First scan the bare key 590 590 key = scan(KEY_REGEXP) or return … … 604 604 # After we see a key, we must look ahead to determine our next action. Cases: 605 605 # 606 606 # [] follows the key. Then the value must be an array. 607 # = follows the key. (A value comes next) 608 # & or the end of string follows the key. Then the key is a flag. 609 # otherwise, a hash follows the key. 607 # [? follows the key. Then the value must be an hash. 608 # otherwise, we're done (or the format is invalid -- not handled) 610 609 def post_key_check(key) 611 610 if scan(/\[\]/) # a[b][] indicates that b is an array 612 611 container(key, Array) 613 612 nil 614 613 elsif check(/\[[^\]]/) # a[b] indicates that a is a hash 615 container(key, Hash )614 container(key, HashWithIndifferentAccess) 616 615 nil 617 616 else # End of key? We do nothing. 618 617 key … … 634 633 635 634 # Bind a key (which may be nil for items in an array) to the provided value. 636 635 def bind(key, value) 637 if top.is_a? Array636 if top.is_a?(Array) 638 637 if key 639 638 if top[-1].is_a?(Hash) && ! top[-1].key?(key) 640 639 top[-1][key] = value