Hi,
I found some bugs of REXML 3.1.6 related XPath.
The following code raises an exception:
require 'rexml/document'
source = <<-XML
<a>
<b number='1' str='abc'>TEXT1</b>
<c number='1'/>
<c number='2' str='def'>
<b number='3'/>
<d number='1' str='abc'>TEXT2</d>
<b number='2'><!--COMMENT--></b>
</c>
</a>
XML
doc = REXML::Document.new(source)
predicate = "count(child::node()|following-sibling::node()|preceding-sibling::node())=0"
p REXML::XPath.match(doc, "/descendant-or-self::node()[#{predicate}]")
The exception is the following:
/usr/lib/ruby/1.8/rexml/xpath_parser.rb:335:in `expr': undefined method `children' for nil:NilClass (NoMethodError)
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:334:in `each'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:334:in `expr'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:422:in `expr'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:421:in `expr'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:447:in `expr'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:445:in `collect'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:445:in `expr'
from /usr/lib/ruby/1.8/rexml/encoding.rb:47:in `each_with_index'
... 14 levels...
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:125:in `match'
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:56:in `parse'
from /usr/lib/ruby/1.8/rexml/xpath.rb:63:in `match'
from rexml-3.1.6-xpath-bug.rb:21
I'll attach a patch of test case and fixing.
Thanks,
rexml-3.1.6-siblings-bug.diff (2.37 KB)
···
--
kou