Hi,
I found some bugs of REXML 3.1.6 related XPath.
The following code raises an exception:
require ‘rexml/document’
source = <<-XML
TEXT1
TEXT2
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,