Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   REXML 3.1.6 has a XPath parser problem (http://www.velocityreviews.com/forums/t836966-rexml-3-1-6-has-a-xpath-parser-problem.html)

Kouhei Sutou 01-06-2007 06:59 AM

REXML 3.1.6 has a XPath parser problem
 
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,
--
kou



All times are GMT. The time now is 11:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.