From d93e68a44b063a2d0b939d88649bd57b7614c063 Mon Sep 17 00:00:00 2001 From: bahtya Date: Sun, 5 Apr 2026 10:20:29 +0800 Subject: [PATCH] Fix BoolWithInverseFlag.String() panic when FlagStringer returns no tab When FlagStringer returns a string without a tab character, strings.Index returns -1, causing out[i:] to panic with index out of range. Add guard to return the string as-is when no tab is found. Fixes #2303 --- flag_bool_with_inverse.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flag_bool_with_inverse.go b/flag_bool_with_inverse.go index 272dd98fec..edbd2b7063 100644 --- a/flag_bool_with_inverse.go +++ b/flag_bool_with_inverse.go @@ -171,6 +171,9 @@ func (bif *BoolWithInverseFlag) String() string { out := FlagStringer(bif) i := strings.Index(out, "\t") + if i == -1 { + return out + } prefix := "--"