Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1369 from arunagw/3-0-stable

File From Xml is working now. #3-0-stable
  • Loading branch information...
commit 3332b495b9c4bd2ee82a3bedb0f3e952fd7bf0f1 2 parents c3cbd2c + d8b6fcb
@tenderlove tenderlove authored
View
13 activesupport/lib/active_support/xml_mini/jdom.rb
@@ -41,7 +41,7 @@ def parse(data)
xml_string_reader = StringReader.new(data)
xml_input_source = InputSource.new(xml_string_reader)
doc = @dbf.new_document_builder.parse(xml_input_source)
- merge_element!({}, doc.document_element)
+ merge_element!({CONTENT_KEY => ''}, doc.document_element)
end
end
@@ -54,9 +54,14 @@ def parse(data)
# element::
# XML element to merge into hash
def merge_element!(hash, element)
+ delete_empty(hash)
merge!(hash, element.tag_name, collapse(element))
end
+ def delete_empty(hash)
+ hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ''
+ end
+
# Actually converts an XML document element into a data structure.
#
# element::
@@ -84,6 +89,7 @@ def collapse(element)
# element::
# XML element whose texts are to me merged into the hash
def merge_texts!(hash, element)
+ delete_empty(hash)
text_children = texts(element)
if text_children.join.empty?
hash
@@ -128,8 +134,9 @@ def get_attributes(element)
attribute_hash = {}
attributes = element.attributes
for i in 0...attributes.length
- attribute_hash[attributes.item(i).name] = attributes.item(i).value
- end
+ attribute_hash[CONTENT_KEY] ||= ''
+ attribute_hash[attributes.item(i).name] = attributes.item(i).value
+ end
attribute_hash
end
View
28 activesupport/test/xml_mini/jdom_engine_test.rb
@@ -16,20 +16,20 @@ def teardown
XmlMini.backend = @default_backend
end
- # def test_file_from_xml
- # hash = Hash.from_xml(<<-eoxml)
- # <blog>
- # <logo type="file" name="logo.png" content_type="image/png">
- # </logo>
- # </blog>
- # eoxml
- # assert hash.has_key?('blog')
- # assert hash['blog'].has_key?('logo')
- #
- # file = hash['blog']['logo']
- # assert_equal 'logo.png', file.original_filename
- # assert_equal 'image/png', file.content_type
- # end
+ def test_file_from_xml
+ hash = Hash.from_xml(<<-eoxml)
+ <blog>
+ <logo type="file" name="logo.png" content_type="image/png">
+ </logo>
+ </blog>
+ eoxml
+ assert hash.has_key?('blog')
+ assert hash['blog'].has_key?('logo')
+
+ file = hash['blog']['logo']
+ assert_equal 'logo.png', file.original_filename
+ assert_equal 'image/png', file.content_type
+ end
def test_exception_thrown_on_expansion_attack
assert_raise NativeException do
Please sign in to comment.
Something went wrong with that request. Please try again.