diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb index faf373c8..cb2f5c67 100644 --- a/lib/rexml/parsers/xpathparser.rb +++ b/lib/rexml/parsers/xpathparser.rb @@ -411,7 +411,8 @@ def Predicate path, parsed while path[0] == ?[ path, expr = get_group(path) predicates << expr[1..-2] if expr - path = path.lstrip + stripped_path = path.lstrip + path = stripped_path if stripped_path.start_with?("[") end predicates.each{ |pred| preds = [] diff --git a/test/xpath/test_base.rb b/test/xpath/test_base.rb index f0f53219..a7d712fb 100644 --- a/test/xpath/test_base.rb +++ b/test/xpath/test_base.rb @@ -209,6 +209,19 @@ def test_predicates assert_equal "b", XPath::first( @@doc, "//b[@x]" ).name end + def test_word_operators_after_predicates + doc = Document.new("62") + assert_equal([true], XPath.match(doc, "//v[1] and true()")) + assert_equal([true], XPath.match(doc, "//missing[1] or true()")) + assert_equal([2.0], XPath.match(doc, "/r/v[1] div 3")) + assert_equal([2.0], XPath.match(doc, "/r/v[1] mod 4")) + assert_equal([true], XPath.match(doc, "//v[position() <= 2] [1] and true()")) + assert_equal([true], XPath.match(doc, "//missing[1] [1] or true()")) + assert_equal([2.0], XPath.match(doc, "/r/v[position() <= 2] [1] div 3")) + assert_equal([2.0], XPath.match(doc, "/r/v[position() <= 2] [1] mod 4")) + assert_equal([], XPath.match(doc, "/r/v[../v[1] div 3 = 3]")) + end + def test_node_type doc = Document.new "text" #res = XPath::first(doc.root, "text()")