From 96baf08499f03b077df7e563f812e90d874b3fb5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 15 May 2012 15:05:18 -0700 Subject: [PATCH] * Nokogiri::XML::Text#to_ary returns an array with the node text. fixes #679 --- CHANGELOG.rdoc | 1 + lib/nokogiri/xml/text.rb | 4 ++++ test/xml/test_text.rb | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index c97d58bcf2..196720885d 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -23,6 +23,7 @@ * JRuby 1.9 mode causes dead lock while running rake #571 * HTML::Document#meta_encoding does not raise exception on docs with malformed content-type. #655 + * Nokogiri::XML::Text#to_ary returns an array with the node text. #679 == 1.5.2 / 2012-03-09 diff --git a/lib/nokogiri/xml/text.rb b/lib/nokogiri/xml/text.rb index 99eecb1bff..5ab96f9530 100644 --- a/lib/nokogiri/xml/text.rb +++ b/lib/nokogiri/xml/text.rb @@ -4,6 +4,10 @@ class Text < Nokogiri::XML::CharacterData def content=(string) self.native_content = string.to_s end + + def to_ary + [self.text] + end end end end diff --git a/test/xml/test_text.rb b/test/xml/test_text.rb index 14f1d911f9..d043ad6251 100644 --- a/test/xml/test_text.rb +++ b/test/xml/test_text.rb @@ -3,6 +3,12 @@ module Nokogiri module XML class TestText < Nokogiri::TestCase + def test_ary + doc = Nokogiri.XML " foo something bar bazz " + node = doc.root.children[2] + assert_equal [node.text], Array(node) + end + def test_css_path doc = Nokogiri.XML " foo something bar bazz " node = doc.root.children[2]