Ignore comment nodes in NodeSet#text.
This commit is contained in:
parent
99be3182ae
commit
ff8a4ad3aa
|
@ -240,7 +240,7 @@ module Oga
|
|||
alias_method :attr, :attribute
|
||||
|
||||
##
|
||||
# Returns the text of all nodes in the set.
|
||||
# Returns the text of all nodes in the set, ignoring comment nodes.
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
|
@ -248,7 +248,7 @@ module Oga
|
|||
text = ''
|
||||
|
||||
@nodes.each do |node|
|
||||
if node.respond_to?(:text)
|
||||
if node.respond_to?(:text) and !node.is_a?(Comment)
|
||||
text << node.text
|
||||
end
|
||||
end
|
||||
|
|
|
@ -310,19 +310,21 @@ describe Oga::XML::NodeSet do
|
|||
|
||||
context '#text' do
|
||||
before do
|
||||
child = Oga::XML::Text.new(:text => 'foo')
|
||||
child = Oga::XML::Text.new(:text => 'foo')
|
||||
comment = Oga::XML::Comment.new(:text => 'bar')
|
||||
cdata = Oga::XML::Cdata.new(:text => 'baz')
|
||||
text = Oga::XML::Text.new(:text => "\nbar")
|
||||
|
||||
@el = Oga::XML::Element.new(
|
||||
:name => 'a',
|
||||
:children => described_class.new([child])
|
||||
:children => described_class.new([child, comment, cdata])
|
||||
)
|
||||
|
||||
@txt = Oga::XML::Text.new(:text => "\nbar")
|
||||
@set = described_class.new([@el, @txt])
|
||||
@set = described_class.new([@el, text])
|
||||
end
|
||||
|
||||
example 'return the text of all nodes' do
|
||||
@set.text.should == "foo\nbar"
|
||||
@set.text.should == "foobaz\nbar"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue