Forum: Ruby REXML 3.1.6 has XPath problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2006-12-30 05:00
(Received via mailing list)
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,
05e4e83c87a5700958fcb3efa8951a06?d=identicon&s=25 vasudevram (Guest)
on 2006-12-30 18:56
(Received via mailing list)
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
http://www.dancingbison.com
http://sourceforge.net/projects/xtopdf
http://jugad.livejournal.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2006-12-31 04:01
(Received via mailing list)
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/...

Thanks,
05e4e83c87a5700958fcb3efa8951a06?d=identicon&s=25 vasudevram (Guest)
on 2007-01-02 11:21
(Received via mailing list)
Kouhei Sutou wrote:
> --
> kou

Thanks for the reply.
Vasudev
This topic is locked and can not be replied to.