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
3 changes: 2 additions & 1 deletion lib/rexml/parsers/xpathparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
13 changes: 13 additions & 0 deletions test/xpath/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<r><v>6</v><v>2</v></r>")
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 "<a><?foo bar?><!--comment-->text</a>"
#res = XPath::first(doc.root, "text()")
Expand Down
Loading