From 2e9903c203939fc6224ab1a2f254b264d53a2529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Fri, 14 Aug 2026 13:43:54 +0200 Subject: [PATCH] Don't use RegExp match for `substring-after()` XPath function XPath expects `string` match according to specification: https://www.w3.org/TR/1999/REC-xpath-19991116/#function-substring-after So these two should not provide the same result (while they previously did): ~~~ REXML::Functions::substring_after("helloworld","hello") REXML::Functions::substring_after("helloworld","hel.o") ~~~ --- lib/rexml/functions.rb | 9 +++++++-- test/functions/test_base.rb | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 106a21ee..f84b846b 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -205,8 +205,13 @@ def substring_before( string, test ) # Kouhei fixed this too def substring_after( string, test ) ruby_string = string(string) - return $1 if ruby_string =~ /#{test}(.*)/ - "" + ruby_test = string(test) + ruby_index = ruby_string.index(ruby_test) + if ruby_index.nil? + "" + else + ruby_string[(ruby_index + ruby_test.length)..-1] + end end # Take equal portions of Mike Stok and Sean Russell; mix diff --git a/test/functions/test_base.rb b/test/functions/test_base.rb index 44f07c11..b63f3d5a 100644 --- a/test/functions/test_base.rb +++ b/test/functions/test_base.rb @@ -126,6 +126,8 @@ def test_substring def test_substring_angrez testString = REXML::Functions::substring_after("helloworld","hello") assert_equal( 'world', testString ) + testString = REXML::Functions::substring_after("helloworld","hel.o") + assert_equal( '', testString ) end def test_translate