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 = “
  • 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,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs