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
|
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]
|
# @return [String]
|
||||||
#
|
#
|
||||||
|
@ -248,7 +248,7 @@ module Oga
|
||||||
text = ''
|
text = ''
|
||||||
|
|
||||||
@nodes.each do |node|
|
@nodes.each do |node|
|
||||||
if node.respond_to?(:text)
|
if node.respond_to?(:text) and !node.is_a?(Comment)
|
||||||
text << node.text
|
text << node.text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -311,18 +311,20 @@ describe Oga::XML::NodeSet do
|
||||||
context '#text' do
|
context '#text' do
|
||||||
before 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(
|
@el = Oga::XML::Element.new(
|
||||||
:name => 'a',
|
: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, text])
|
||||||
@set = described_class.new([@el, @txt])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return the text of all nodes' do
|
example 'return the text of all nodes' do
|
||||||
@set.text.should == "foo\nbar"
|
@set.text.should == "foobaz\nbar"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue