From 7c8fa8f2386240138f62227449877e305155b645 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Sat, 30 May 2026 20:44:54 -0700 Subject: [PATCH] fix(stringx): reject start > stop in Substr to prevent slice panic Signed-off-by: Sai Asish Y --- core/stringx/strings.go | 2 +- core/stringx/strings_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/stringx/strings.go b/core/stringx/strings.go index dadf2c52c157..f726c2414c17 100644 --- a/core/stringx/strings.go +++ b/core/stringx/strings.go @@ -128,7 +128,7 @@ func Substr(str string, start, stop int) (string, error) { return "", ErrInvalidStartPosition } - if stop < 0 || stop > length { + if stop < 0 || stop > length || start > stop { return "", ErrInvalidStopPosition } diff --git a/core/stringx/strings_test.go b/core/stringx/strings_test.go index 0adcaf3ab46e..10039c06a9eb 100644 --- a/core/stringx/strings_test.go +++ b/core/stringx/strings_test.go @@ -344,6 +344,13 @@ func TestSubstr(t *testing.T) { err: ErrInvalidStopPosition, expect: "", }, + { + input: "hello", + start: 3, + stop: 2, + err: ErrInvalidStopPosition, + expect: "", + }, } for _, each := range cases {