Permalink
Browse files

attributes no longer disappear if a tag contains whitespace

old:
Hash.from_xml("<tag foo='bar'>\n</tag>")
=> {"tag"=>"\n"}

new:
Hash.from_xml("<tag foo='bar'>\n</tag>")
=> {"tag"=>{"foo"=>"bar", "__content__"=>"\n"}
  • Loading branch information...
1 parent ada550d commit 7660e7cb4df69ad127661ad87f495a3b212170b9 @indirect indirect committed with dhh Apr 14, 2011
@@ -108,7 +108,7 @@ def typecast_xml_value(value)
raise "can't typecast #{entries.inspect}"
end
end
- elsif value.has_key?("__content__")
+ elsif value.has_key?("__content__") && value["__content__"].gsub(/\s/, '').present?
content = value["__content__"]
if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
parser.arity == 1 ? parser.call(content) : parser.call(content, value)
@@ -889,6 +889,15 @@ def test_file_from_xml_with_defaults
assert_equal 'application/octet-stream', file.content_type
end
+ def test_tag_with_attrs_and_whitespace
+ xml = <<-XML
+ <blog name="bacon is the best">
+ </blog>
+ XML
+ hash = Hash.from_xml(xml)
+ assert_equal "bacon is the best", hash['blog']['name']
+ end
+
def test_xsd_like_types_from_xml
bacon_xml = <<-EOT
<bacon>

0 comments on commit 7660e7c

Please sign in to comment.