From d4882c1da06316a92c43505ed25ea8c66d37f272 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Sat, 20 Jun 2026 21:13:44 -0700 Subject: [PATCH] fix(stringx): reject start > stop in Substr to prevent slice panic (#5616) 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 e1afe9424..3915955c6 100644 --- a/core/stringx/strings.go +++ b/core/stringx/strings.go @@ -132,7 +132,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 aa84db9dd..d33bf78cb 100644 --- a/core/stringx/strings_test.go +++ b/core/stringx/strings_test.go @@ -356,6 +356,13 @@ func TestSubstr(t *testing.T) { err: ErrInvalidStopPosition, expect: "", }, + { + input: "hello", + start: 3, + stop: 2, + err: ErrInvalidStopPosition, + expect: "", + }, } for _, each := range cases {