Skip to content

Commit e2968dc

Browse files
committed
Add a deprecation warning for REXML::XPath.each/find/match with nodeset
1 parent eccf0f5 commit e2968dc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/rexml/xpath_parser.rb

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ def first( path_stack, node )
137137

138138

139139
def match(path_stack, node)
140+
if node.is_a?(Array)
141+
Kernel.warn("REXML::XPath.each, REXML::XPath.first, REXML::XPath.match dropped support for nodeset...", uplevel: 1)
142+
return [] if node.empty?
143+
node = node.first
144+
end
140145
nodeset = [XPathNode.new(node, position: 1)]
141146
result = expr(path_stack, nodeset)
142147
case result

test/xpath/test_base.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1159,5 +1159,15 @@ def test_or_and
11591159
end
11601160
assert_equal(["/"], hrefs, "Bug #3842 [ruby-core:32447]")
11611161
end
1162+
1163+
def test_match_with_deprecated_usage
1164+
verbose, $VERBOSE = $VERBOSE, nil
1165+
doc = Document.new("<a><b/></a>")
1166+
assert_equal(['b'], XPath.match([doc, doc], '//b').map(&:name))
1167+
assert_equal(['b'], XPath.match([doc], '//b').map(&:name))
1168+
assert_equal([], XPath.match([], '//b').map(&:name))
1169+
ensure
1170+
$VERBOSE = verbose
1171+
end
11621172
end
11631173
end

0 commit comments

Comments
 (0)