fix(strutil): preserve IndexOffset not-found results (#367)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-23 18:14:24 +08:00
1 parent 34c7e36d29
commit 99ed115de4
2 files changed
+6 -1

No files matched your search

+4 -1
View File
@@ -483,7 +483,10 @@ func IndexOffset(str string, substr string, idxFrom int) int {
return -1
}
return strings.Index(str[idxFrom:], substr) + idxFrom
if index := strings.Index(str[idxFrom:], substr); index >= 0 {
return index + idxFrom
}
return -1
}
// ReplaceWithMap returns a copy of `str`,
+2
View File
@@ -660,6 +660,8 @@ func TestIndexOffset(t *testing.T) {
{str, "d", len(str) - 1, len(str) - 1},
{str, "d", len(str), -1},
{str, "f", -1, -1},
{str, "missing", 5, -1},
{str, "foo", 5, -1},
}
for _, tt := range tests {