REXML 3.1.6 has a XPath parser problem


K

Kouhei Sutou

Hi,

XPath parser of REXML 3.1.6 has a problem related white
space. We can meet the problem by function call with string
which starts with "\nALPHABET".

The following is patch and test case:

diff -ru rexml_3.1.6.orig/src/rexml/parsers/xpathparser.rb rexml_3.1.6/src/rexml/parsers/xpathparser.rb
--- rexml_3.1.6.orig/src/rexml/parsers/xpathparser.rb 2006-11-28 22:54:57.000000000 +0900
+++ rexml_3.1.6/src/rexml/parsers/xpathparser.rb 2007-01-06 15:52:41.000000000 +0900
@@ -551,7 +551,7 @@
end
end
#puts "BEFORE WITH '#{rest}'"
- rest = LocationPath(rest, n) if rest =~ /^[\/\.\@\[\w_*]/
+ rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w_*]/
parsed.concat(n)
return rest
end
diff -ru rexml_3.1.6.orig/test/functions.rb rexml_3.1.6/test/functions.rb
--- rexml_3.1.6.orig/test/functions.rb 2006-11-28 22:54:56.000000000 +0900
+++ rexml_3.1.6/test/functions.rb 2007-01-06 15:53:40.000000000 +0900
@@ -212,4 +212,12 @@
assert_equal( "A", REXML::XPath.first(document, '//b[.="A"]').text )
assert_equal( "1", REXML::XPath.first(document, '//b[.="1"]').text )
end
+
+ def test_normalize_space
+ source = "<a><!--COMMENT A--><b><!-- COMMENT A --></b></a>"
+ doc = REXML::Document.new(source)
+ predicate = "string(.)=normalize_space('\nCOMMENT \n A \n\n ')"
+ m = REXML::XPath.match(doc, "//comment()[#{predicate}]")
+ assert_equal( [REXML::Comment.new("COMMENT A")], m )
+ end
end


Thanks,
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top