diff options
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/cgi_ext/cgi_methods.rb | 2 | ||||
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/indifferent_access.rb | 10 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 5 |
6 files changed, 20 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 13d362725e..982d236472 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that parameters from XML should also be presented in a hash with indifferent access [DHH] + * Tweak template format rules so that the ACCEPT header is only used if it's text/javascript. This is so ajax actions without a :format param get recognized as Mime::JS. [Rick] * The default respond_to blocks don't set a specific extension anymore, so that both 'show.rjs' and 'show.js.rjs' will work. [Rick] diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb index abf70cc76a..250c3272b9 100755 --- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb +++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb @@ -49,7 +49,7 @@ class CGIMethods #:nodoc: when Proc strategy.call(raw_post_data) when :xml_simple, :xml_node - raw_post_data.blank? ? {} : Hash.from_xml(raw_post_data) + raw_post_data.blank? ? {} : Hash.from_xml(raw_post_data).with_indifferent_access when :yaml YAML.load(raw_post_data) end diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index e0108f27bc..55f57b1180 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Hash#with_indifferent_access now also converts hashes kept in arrays to indifferent access (makes it easier to treat HTML and XML parameters the same) [DHH] + * Hash#to_xml supports YAML attributes. #7502 [jonathan] * Refactor ActiveSupport::JSON to be less obtuse. Add support for JSON decoding by way of Syck with ActiveSupport::JSON.decode(json_string). Prevent hash keys that are JavaScript reserved words from being unquoted during encoding. [Sam Stephenson] diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index bbfc2502a1..07d50df6ba 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -111,7 +111,7 @@ module ActiveSupport #:nodoc: 'forcecontent' => true, 'keeproot' => true, 'contentkey' => '__content__') - )) + )) end def create_from_xml(xml) diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 6c7e6d76ac..01d5b3a6a3 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -73,8 +73,16 @@ class HashWithIndifferentAccess < Hash def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key end + def convert_value(value) - value.is_a?(Hash) ? value.with_indifferent_access : value + case value + when Hash + value.with_indifferent_access + when Array + value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e } + else + value + end end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 5a5bd7fe5a..63caed7d99 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -183,6 +183,11 @@ class HashExtTest < Test::Unit::TestCase assert_equal '1234', roundtrip.default end + def test_indifferent_hash_with_array_of_hashes + hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] }}.with_indifferent_access + assert_equal "1", hash[:urls][:url].first[:address] + end + def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash h = HashWithIndifferentAccess.new h[:first] = 1 |