diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb index a6d76fdc..b0b82e2f 100644 --- a/lib/rexml/parsers/xpathparser.rb +++ b/lib/rexml/parsers/xpathparser.rb @@ -591,14 +591,15 @@ def PathExpr path, parsed path = path.lstrip n = [] rest = FilterExpr( path, n ) - if rest != path + if rest == path + rest = LocationPath(rest, n) + else if rest and rest[0] == ?/ rest = RelativeLocationPath(rest, n) parsed.concat(n) return rest end end - rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w*]/ parsed.concat(n) rest end diff --git a/test/parser/test_xpath.rb b/test/parser/test_xpath.rb index 5d62afee..6a4a6c48 100644 --- a/test/parser/test_xpath.rb +++ b/test/parser/test_xpath.rb @@ -111,5 +111,18 @@ def test_filter_string_double_quote abbreviate("a/b[attribute::name='double \" quote']/c")) end end + + def test_mult_and_spaces + parser = REXML::Parsers::XPathParser.new + assert_equal(parser.parse("1 * 2 * 3"), parser.parse("1*2*3")) + assert_equal(parser.parse("a[( ( 1 + 2 ) * 3 + 4 * ( 5 + 6 ) ) * 7 < 8]"), parser.parse("a[((1+2)*3+4*(5+6))*7<8]")) + # number(a/b) * 2 + assert_equal(parser.parse("(a/b) * 2"), parser.parse("(a/b)*2")) + assert_equal(parser.parse("a/b * 2"), parser.parse("a/b*2")) + # number(a/b/*) * 2 + assert_equal(parser.parse("a/b/* * 2"), parser.parse("a/b/**2")) + # number(*) * number(*/*) * number(*) + assert_equal(parser.parse("* * */* * *"), parser.parse("***/***")) + end end end