diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/rexml/formatters/default.rb | 4 | ||||
-rw-r--r-- | test/rexml/test_document.rb | 19 |
3 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,9 @@ +Sun Nov 29 06:37:53 2009 Aaron Patterson <tenderlove@ruby-lang.org> + + * lib/rexml/formatters/default.rb (write_attribute): fix an + exception when printing a document when duplicate namespaced + attributes exist. Thanks, Alexey Froloff [ruby-core:2389] + Sat Nov 28 09:05:53 2009 Yukihiro Matsumoto <matz@ruby-lang.org> * vm_eval.c (check_funcall_failed): should rescue user raised diff --git a/lib/rexml/formatters/default.rb b/lib/rexml/formatters/default.rb index 56a1d93783..db44453e1e 100644 --- a/lib/rexml/formatters/default.rb +++ b/lib/rexml/formatters/default.rb @@ -63,7 +63,9 @@ module REXML def write_element( node, output ) output << "<#{node.expanded_name}" - node.attributes.to_a.sort_by {|attr| attr.name}.each do |attr| + node.attributes.to_a.map { |a| + Hash === a ? a.values : a + }.flatten.sort_by {|attr| attr.name}.each do |attr| output << " " attr.write( output ) end unless node.attributes.empty? diff --git a/test/rexml/test_document.rb b/test/rexml/test_document.rb index 0261e80b74..a35fce7dca 100644 --- a/test/rexml/test_document.rb +++ b/test/rexml/test_document.rb @@ -2,6 +2,25 @@ require "rexml/document" require "test/unit" class REXML::TestDocument < Test::Unit::TestCase + def test_version_attributes_to_s + doc = REXML::Document.new(<<-eoxml) + <?xml version="1.0" encoding="UTF-8" standalone="no"?> + <svg id="svg2" + xmlns:sodipodi="foo" + xmlns:inkscape="bar" + sodipodi:version="0.32" + inkscape:version="0.44.1" + > + </svg> + eoxml + + string = doc.to_s + assert_match('xmlns:sodipodi', string) + assert_match('xmlns:inkscape', string) + assert_match('sodipodi:version', string) + assert_match('inkscape:version', string) + end + def test_new doc = REXML::Document.new(<<EOF) <?xml version="1.0" encoding="UTF-8"?> |