From 2175b88e23427e7fc7f05afb4592785625e9bcc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=A8=E4=BA=AE?= Date: Thu, 11 Jan 2024 19:07:05 +0800 Subject: [PATCH 1/2] Update functions.go **Issue Description:** The current `strSubstring` function has a potential issue with the stop index check. The condition `if stop >= len(str)` may result in undesired behavior, especially when attempting to include the last character in the substring. Since the slicing operation `v = str[start : stop+1]` is left-closed and right-open, the character at the `stop` index is excluded. **Proposed Solution:** To address this, it is suggested to modify the condition to `if stop > len(str) || stop < 0` for a more accurate check on invalid stop indices. Additionally, the error message should be updated to reflect this change: ```go if stop > len(str) || stop < 0 { return nil, fmt.Errorf("invalid stop index for string in strSubstring: %d", stop) } v = str[start : stop+1] ``` This modification ensures correct substring extraction, even when attempting to include the character at the stop index. --- tick/stateful/functions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tick/stateful/functions.go b/tick/stateful/functions.go index 6e8e42717..9310fc976 100644 --- a/tick/stateful/functions.go +++ b/tick/stateful/functions.go @@ -726,7 +726,7 @@ func (m strSubstring) Call(args ...interface{}) (v interface{}, err error) { return nil, fmt.Errorf("stop index too large for string in strSubstring: %d", stop) } - v = str[start:stop] + v = str[start:stop + 1] return } From ae67ee1241d43c35d948c5ca09874eec5f0e212a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=A8=E4=BA=AE?= Date: Thu, 11 Jan 2024 19:22:29 +0800 Subject: [PATCH 2/2] Update functions.go --- tick/stateful/functions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tick/stateful/functions.go b/tick/stateful/functions.go index 9310fc976..c7eddddd8 100644 --- a/tick/stateful/functions.go +++ b/tick/stateful/functions.go @@ -726,7 +726,7 @@ func (m strSubstring) Call(args ...interface{}) (v interface{}, err error) { return nil, fmt.Errorf("stop index too large for string in strSubstring: %d", stop) } - v = str[start:stop + 1] + v = str[start : stop+1] return }