REXML 3.1.6 has XPath problems

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 methodchildren’ 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:inexpr’
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:422:in expr' from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:421:inexpr’
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:447:in expr' from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:445:incollect’
from /usr/lib/ruby/1.8/rexml/xpath_parser.rb:445:in expr' from /usr/lib/ruby/1.8/rexml/encoding.rb:47:ineach_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:inparse’
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,

Kouhei S. wrote:

What are the problems that you’ve seen?
Like to know as I use REXML. Don’t remember the version I use right
now, will check.

Thanks
Vasudev

Vasudev Ram
Dancing Bison Enterprises
Software consulting and training
http://www.dancingbison.com
http://sourceforge.net/projects/xtopdf
http://jugad.livejournal.com

Hi,

In [email protected]
“Re: REXML 3.1.6 has XPath problems” on Sun, 31 Dec 2006 02:55:09
+0900,
“vasudevram” [email protected] wrote:

Kouhei S. wrote:

What are the problems that you’ve seen?
Like to know as I use REXML. Don’t remember the version I use right
now, will check.

My last mail was broken. You can see the (broken) mail in
blade:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/231756

Thanks,

Kouhei S. wrote:


kou

Thanks for the reply.
Vasudev