Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

XML attributes no longer disappear if a tag contains whitespace #272

Closed
wants to merge 1 commit into from

2 participants

André Arko David Heinemeier Hansson
André Arko

before:

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

now:

Hash.from_xml("<tag foo='bar'>\n</tag>")
=> {"tag"=>{"foo"=>"bar", "__content__"=>"\n"}
André Arko indirect 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"}
78d971c
David Heinemeier Hansson
Owner

Thanks! Applied.

David Heinemeier Hansson dhh closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2011
  1. André Arko

    attributes no longer disappear if a tag contains whitespace

    indirect authored
    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"}
This page is out of date. Refresh to see the latest.
2  activesupport/lib/active_support/core_ext/hash/conversions.rb
View
@@ -96,7 +96,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)
9 activesupport/test/core_ext/hash_ext_test.rb
View
@@ -857,6 +857,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>
Something went wrong with that request. Please try again.