Permalink
Browse files

Fixed that parameters from XML should also be presented in a hash wit…

…h 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
  • Loading branch information...
1 parent 7722e2b commit a0e78f7442143c1366de06ec28342ad728870a1c @dhh dhh committed Apr 16, 2007
View
@@ -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 @@ def parse_formatted_request_parameters(mime_type, raw_post_data)
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
View
@@ -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 @@ def from_xml(xml)
'forcecontent' => true,
'keeproot' => true,
'contentkey' => '__content__')
- ))
+ ))
end
def create_from_xml(xml)
@@ -73,8 +73,16 @@ def to_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 @@ def test_indifferent_to_hash
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

0 comments on commit a0e78f7

Please sign in to comment.