From 97bde5e275defa66a748a029b9ec8de2a68ffb07 Mon Sep 17 00:00:00 2001 From: tompng Date: Tue, 25 Aug 2026 22:42:16 +0900 Subject: [PATCH] Stop fallback to XPath.match in FunctionsClass#send Return value of xpath function should be either number, string, boolean or nodeset. But the fallback path returns `XPath.match(unregistered_function_name)` which may return number/string/boolean wrapped in an array. Instead of rejecting these invalid value types or unwrapping the array, simply removing the XPath-noncompliant behavior is better. --- lib/rexml/functions.rb | 2 +- test/functions/test_base.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 16177263..a558ccdf 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -428,7 +428,7 @@ def send(name, *args) else # TODO: Maybe, this is not XPath spec behavior. # This behavior must be reconsidered. - XPath.match(@context[:node], name.to_s) + [] end end end diff --git a/test/functions/test_base.rb b/test/functions/test_base.rb index b63f3d5a..4e1bf483 100644 --- a/test/functions/test_base.rb +++ b/test/functions/test_base.rb @@ -299,8 +299,10 @@ def test_nonexistent_function doc = Document.new("") # TODO: Maybe, this is not XPath spec behavior. # This behavior must be reconsidered. - assert_equal(doc.root.elements[1], - XPath::first(doc.root, "nonexistent()")) + assert_nil(XPath::first(doc.root, "nonexistent()")) + assert_empty(XPath::match(doc.root, "nonexistent()")) + assert_empty(XPath::match(doc, "42()/*")) + assert_empty(Functions.send('42')) end end end