From 241f953c53df1532e7a0635a7efeb1ccf70099c8 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Wed, 17 Jun 2026 12:27:16 -0700 Subject: [PATCH] Support string-length() XPath function without an argument Signed-off-by: Sai Asish Y --- lib/rexml/functions.rb | 5 ++--- test/functions/test_base.rb | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index 8881c3fa..1a0f85ec 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -254,9 +254,8 @@ def substring( string, start, length=nil ) ruby_string[ruby_start,ruby_length] end - # UNTESTED - def string_length( string ) - string(string).length + def string_length( object=@context[:node] ) + string(object).length end def normalize_space( object=@context[:node] ) diff --git a/test/functions/test_base.rb b/test/functions/test_base.rb index eb67fa3f..f2c53d43 100644 --- a/test/functions/test_base.rb +++ b/test/functions/test_base.rb @@ -70,6 +70,12 @@ def test_string_length assert_equal 3, set.size, "nodes with names length > 3" end + def test_string_length_without_argument + doc = Document.new("123123412345") + set = doc.elements.to_a("//item[string-length()=4]") + assert_equal ["1234"], set.collect(&:text) + end + # Test provided by Mike Stok def test_contains source = <<-EOF