Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'REXMLUtilityNode-type-bug' of https://github.com/admgre…

…/crack into admgre-REXMLUtilityNode-type-bug

Conflicts:
	test/xml_test.rb
  • Loading branch information...
commit 0f06f262368e11ce6428032953e83ec2a6fab37a 2 parents 1c9b13d + b176993
@jnunemaker authored
Showing with 14 additions and 1 deletion.
  1. +2 −1  lib/crack/xml.rb
  2. +12 −0 test/xml_test.rb
View
3  lib/crack/xml.rb
@@ -76,7 +76,8 @@ def add_node(node)
end
def to_hash
- if @type == "file"
+ # ACG: Added a check here to prevent an exception a type == "file" tag has nodes within it
+ if @type == "file" and (@children.first.nil? or @children.first.is_a?(String))
f = StringIO.new((@children.first || '').unpack('m').first)
class << f
attr_accessor :original_filename, :content_type
View
12 test/xml_test.rb
@@ -499,4 +499,16 @@
Marshal.dump(Crack::XML.parse(xml))
end
+
+ it "properly handles a node with type == file that has children" do
+ # Example is an excerpt from a problematic kvm domain config file
+ example_xml = <<-EOT
+ <disk type='file' device='cdrom'>
+ <driver name='qemu' type='raw' cache='none' io='native'/>
+ <source file='/tmp/cdrom.iso'/>
+ </disk>
+ EOT
+
+ Crack::XML.parse(example_xml).must_equal({"disk"=>{"driver"=>{"name"=>"qemu", "type"=>"raw", "cache"=>"none", "io"=>"native"}, "source"=>{"file"=>"/tmp/cdrom.iso"}, "type"=>"file", "device"=>"cdrom"}})
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.