Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rexml/parsers/xpathparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def OrExpr path, parsed
n = []
rest = AndExpr( path, n )
if rest != path
while rest =~ /\A\s*( or )/
while rest =~ /\A\s+(or)\s+/
n = [ :or, n, [] ]
rest = AndExpr( $', n[-1] )
end
Expand All @@ -452,7 +452,7 @@ def AndExpr path, parsed
n = []
rest = EqualityExpr( path, n )
if rest != path
while rest =~ /\A\s*( and )/
while rest =~ /\A\s+(and)\s+/
n = [ :and, n, [] ]
rest = EqualityExpr( $', n[-1] )
end
Expand Down Expand Up @@ -542,7 +542,7 @@ def MultiplicativeExpr path, parsed
n = []
rest = UnaryExpr( path, n )
if rest != path
while rest =~ /\A\s*(\*| div | mod )\s*/
while rest =~ /\A\s*(\*|\s(?:div|mod)\s)\s*/
if $1[0] == ?*
n = [ :mult, n, [] ]
elsif $1.include?( "div" )
Expand Down
17 changes: 17 additions & 0 deletions test/parser/test_xpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ def test_qname_must_start_at_the_beginning_of_the_expression
assert_equal([:child, :qname, "a", "b"], parser.parse("a:b"))
end

def test_word_operators_with_any_whitespace
parser = REXML::Parsers::XPathParser.new
# XPath 1.0 allows a space, tab, CR or LF around the operator names
%w[and or div mod].each do |operator|
expected = parser.parse("a #{operator} b")
["\t", "\n", "\r\n", " \t "].each do |space|
assert_equal(expected,
parser.parse("a#{space}#{operator}#{space}b"),
"#{operator} separated by #{space.inspect}")
end
end
assert_equal(parser.parse('//a[@b = 1 and @c = 2]'),
parser.parse("//a[@b = 1\nand\t@c = 2]"))
assert_equal(parser.parse('3 div 2 mod 1'),
parser.parse("3\ndiv\n2\tmod\t1"))
end

def test_unary_minus_with_spaces
parser = REXML::Parsers::XPathParser.new
assert_equal(
Expand Down
Loading