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