From d4a2242ce61441d0901cb750d497be08ff5ef4f6 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Sat, 28 Nov 2009 21:40:59 +0000 Subject: * 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] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/rexml/formatters/default.rb | 4 +++- test/rexml/test_document.rb | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c613855f9..0679e7fbe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Nov 29 06:37:53 2009 Aaron Patterson + + * 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 * 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 56a1d9378..db44453e1 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 0261e80b7..a35fce7dc 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) + + + + 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(< -- cgit