# REXML 3.1.6 has a XPath parser problem

**URL:** <https://www.ruby-forum.com/t/rexml-3-1-6-has-a-xpath-parser-problem/81280>\
**Category:** Ruby\
**Created:** [January 6, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/rexml-3-1-6-has-a-xpath-parser-problem/81280 "2007-01-06T19:31:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kouhei\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f4b2a3/32.png) [@Kouhei\_S](https://www.ruby-forum.com/u/Kouhei_S)\
**Post date:** [January 6, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/rexml-3-1-6-has-a-xpath-parser-problem/81280/1 "2007-01-06T19:31:01Z")

</div>

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,
