Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > REXML 3.1.6 has XPath problems

Reply
Thread Tools

REXML 3.1.6 has XPath problems

 
 
Kouhei Sutou
Guest
Posts: n/a
 
      12-30-2006
----Next_Part(Sat_Dec_30_13_00_32_2006_860)--
Content-Type: Multipart/Mixed;
boundary="--Next_Part(Sat_Dec_30_13_00_32_2006_860)--"

----Next_Part(Sat_Dec_30_13_00_32_2006_860)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

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:ocument.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,
--
kou

----Next_Part(Sat_Dec_30_13_00_32_2006_860)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="rexml-3.1.6-siblings-bug.diff"

diff -ru rexml_3.1.6.orig/src/rexml/xpath_parser.rb rexml_3.1.6/src/rexml/xpath_parser.rb
--- rexml_3.1.6.orig/src/rexml/xpath_parser.rb 2006-11-28 22:54:57.000000000 +0900
+++ rexml_3.1.6/src/rexml/xpath_parser.rb 2006-12-30 12:55:45.000000000 +0900
@@ -351,7 +351,8 @@
when :following_sibling
#puts "FOLLOWING_SIBLING 1: nodeset = #{nodeset}"
results = []
- for node in nodeset
+ nodeset.each do |node|
+ next if node.parent.nil?
all_siblings = node.parent.children
current_index = all_siblings.index( node )
following_siblings = all_siblings[ current_index+1 .. -1 ]
@@ -362,13 +363,14 @@

when receding_sibling
results = []
- for node in nodeset
+ nodeset.each do |node|
+ next if node.parent.nil?
all_siblings = node.parent.children
current_index = all_siblings.index( node )
- preceding_siblings = all_siblings[ 0 .. current_index-1 ].reverse
- #results += expr( path_stack.dclone, preceding_siblings )
+ preceding_siblings = all_siblings[ 0, current_index ].reverse
+ results += preceding_siblings
end
- nodeset = preceding_siblings || []
+ nodeset = results
node_types = ELEMENTS

when receding
diff -ru rexml_3.1.6.orig/test/xpath_test_pred.rb rexml_3.1.6/test/xpath_test_pred.rb
--- rexml_3.1.6.orig/test/xpath_test_pred.rb 2006-11-28 22:54:56.000000000 +0900
+++ rexml_3.1.6/test/xpath_test_pred.rb 2006-12-30 12:53:44.000000000 +0900
@@ -54,4 +54,27 @@
#puts path, @parser.parse( path ).inspect
return m
end
+
+ def test_get_no_siblings_terminal_nodes
+ 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:ocument.new(source)
+ predicate = "count(child::node()|" +
+ "following-sibling::node()|" +
+ "preceding-sibling::node())=0"
+ m = REXML::XPath.match(doc, "/descendant-or-self::node()[#{predicate}]")
+ assert_equal( [REXML::Text.new("TEXT1"),
+ REXML::Text.new("TEXT2"),
+ REXML::Comment.new("COMMENT")],
+ m )
+ end
end

----Next_Part(Sat_Dec_30_13_00_32_2006_860)----
----Next_Part(Sat_Dec_30_13_00_32_2006_860)----

 
Reply With Quote
 
 
 
 
vasudevram
Guest
Posts: n/a
 
      12-30-2006

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

 
Reply With Quote
 
 
 
 
Kouhei Sutou
Guest
Posts: n/a
 
      12-31-2006
Hi,

In <(E-Mail Removed) .com>
"Re: REXML 3.1.6 has XPath problems" on Sun, 31 Dec 2006 02:55:09 +0900,
"vasudevram" <(E-Mail Removed)> 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...by-talk/231756

Thanks,
--
kou

 
Reply With Quote
 
vasudevram
Guest
Posts: n/a
 
      01-02-2007

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...by-talk/231756
>
> Thanks,
> --
> kou


Thanks for the reply.
Vasudev

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REXML::Element.write is deprecated. See REXML::Formatters Phlip Ruby 0 01-15-2008 08:23 PM
REXML 3.1.6 has a XPath parser problem Kouhei Sutou Ruby 0 01-06-2007 06:59 AM
rexml error - REXML::Validation Daniel Berger Ruby 2 10-12-2004 04:19 PM
Rexml xpath question Han Holl Ruby 7 03-06-2004 01:23 PM
soap4r 1.4.8.1 with REXML 2.7.1 - no REXML::VERSION_MAJOR Damphyr Ruby 2 07-16-2003 09:49 AM



Advertisments