提交 7660e7cb 编写于 作者: A Andre Arko 提交者: David Heinemeier Hansson

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"}
上级 ada550d9
......@@ -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>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册