From 4d96ece6ecd27fb6d3695f2503d00ba3d1a9d7ee Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 25 Nov 2007 21:58:24 +0000 Subject: Fix that empty collections should be treated as empty arrays regardless of whitespace for Hash#from_xml (closes #10255) [adamj] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8202 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_support/core_ext/hash/conversions.rb | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/hash/conversions.rb') diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index bbe35c25e4..e196c5d7b9 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -174,20 +174,9 @@ module ActiveSupport #:nodoc: def typecast_xml_value(value) case value.class.to_s when 'Hash' - if value.has_key?("__content__") - content = value["__content__"] - if parser = XML_PARSING[value["type"]] - if parser.arity == 2 - XML_PARSING[value["type"]].call(content, value) - else - XML_PARSING[value["type"]].call(content) - end - else - content - end - elsif value['type'] == 'array' + if value['type'] == 'array' child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway - if entries.nil? + if entries.nil? || (c = value['__content__'] && c.blank?) [] else case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a? @@ -199,6 +188,17 @@ module ActiveSupport #:nodoc: raise "can't typecast #{entries.inspect}" end end + elsif value.has_key?("__content__") + content = value["__content__"] + if parser = XML_PARSING[value["type"]] + if parser.arity == 2 + XML_PARSING[value["type"]].call(content, value) + else + XML_PARSING[value["type"]].call(content) + end + else + content + end elsif value['type'] == 'string' && value['nil'] != 'true' "" # blank or nil parsed values are represented by nil -- cgit v1.2.3