From 691ca41c87d9773be0656c5273154b570f5a3d24 Mon Sep 17 00:00:00 2001 From: rulego-team Date: Wed, 6 Aug 2025 10:55:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96SubstringFunction?= =?UTF-8?q?=E8=B4=9F=E6=95=B0=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/functions_string.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/functions/functions_string.go b/functions/functions_string.go index a2ce194..dac3f49 100644 --- a/functions/functions_string.go +++ b/functions/functions_string.go @@ -295,6 +295,9 @@ func (f *SubstringFunction) Execute(ctx *FunctionContext, args []interface{}) (i } strLen := int64(len(str)) + if start < 0 { + start = strLen + start + } if start < 0 || start >= strLen { return "", nil } @@ -308,6 +311,10 @@ func (f *SubstringFunction) Execute(ctx *FunctionContext, args []interface{}) (i return nil, err } + if length < 0 { + return "", nil + } + end := start + length if end > strLen { end = strLen