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
  <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

Kouhei Sutou 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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hi,

In <1167501251.977592.259910@h40g2000cwb.googlegroups.com>
  "Re: REXML 3.1.6 has XPath problems" on Sun, 31 Dec 2006 02:55:09 +0900,

···

"vasudevram" <vasudevram@gmail.com> wrote:

Kouhei Sutou 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,
--
kou

Kouhei Sutou 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,
--
kou

Thanks for the reply.
Vasudev