ruby-changes:28430
From: kou <ko1@a...>
Date: Fri, 26 Apr 2013 22:56:49 +0900 (JST)
Subject: [ruby-changes:28430] kou:r40482 (trunk): * lib/rexml/element.rb (REXML::Attributes#to_a): Support
kou 2013-04-26 22:56:34 +0900 (Fri, 26 Apr 2013) New Revision: 40482 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40482 Log: * lib/rexml/element.rb (REXML::Attributes#to_a): Support namespaced attributes. [ruby-dev:47277] [Bug #8301] Patch by Ippei Obayashi. Thanks!!! * test/rexml/test_attributes.rb (AttributesTester#test_to_a_with_namespaces): Add a test of the above change. Modified files: trunk/ChangeLog trunk/lib/rexml/element.rb trunk/test/rexml/test_attributes.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 40481) +++ ChangeLog (revision 40482) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Apr 26 22:53:55 2013 Kouhei Sutou <kou@c...> + + * lib/rexml/element.rb (REXML::Attributes#to_a): Support + namespaced attributes. [ruby-dev:47277] [Bug #8301] + Patch by Ippei Obayashi. Thanks!!! + * test/rexml/test_attributes.rb + (AttributesTester#test_to_a_with_namespaces): Add a test of the + above change. + Fri Apr 26 21:48:29 2013 Kouhei Sutou <kou@c...> * lib/rss/atom.rb (RSS::Atom::Entry): Fix indent of document comment. Index: lib/rexml/element.rb =================================================================== --- lib/rexml/element.rb (revision 40481) +++ lib/rexml/element.rb (revision 40482) @@ -987,7 +987,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/element.rb#L987 end def to_a - values.flatten + enum_for(:each_attribute).to_a end # Returns the number of attributes the owning Element contains. Index: test/rexml/test_attributes.rb =================================================================== --- test/rexml/test_attributes.rb (revision 40481) +++ test/rexml/test_attributes.rb (revision 40482) @@ -195,4 +195,26 @@ class AttributesTester < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/rexml/test_attributes.rb#L195 doc.add_element 'a', { 'v' => 'x & y' } assert doc.to_s.index(';') end + + def test_to_a_with_namespaces + document = Document.new(<<-XML) +<root + xmlns:ns1="http://example.org/ns1" + xmlns:ns2="http://example.org/ns2"> + <child + ns1:attribute="ns1" + ns2:attribute="ns2" + attribute="no-ns" + other-attribute="other-value"/> +</root> +XML + child = document.root.elements["child"] + assert_equal([ + "attribute='no-ns'", + "ns1:attribute='ns1'", + "ns2:attribute='ns2'", + "other-attribute='other-value'", + ], + child.attributes.to_a.collect(&:to_string).sort) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/