mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Fixed that parameters from XML should also be presented in a hash with indifferent access [DHH] 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]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6532 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -111,7 +111,7 @@ module ActiveSupport #:nodoc:
|
||||
'forcecontent' => true,
|
||||
'keeproot' => true,
|
||||
'contentkey' => '__content__')
|
||||
))
|
||||
))
|
||||
end
|
||||
|
||||
def create_from_xml(xml)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user