Skip to content

Fix BoolWithInverseFlag.String() panic when no tab in output#2306

Closed
Bahtya wants to merge 1 commit intourfave:mainfrom
Bahtya:fix/bool-inverse-panic
Closed

Fix BoolWithInverseFlag.String() panic when no tab in output#2306
Bahtya wants to merge 1 commit intourfave:mainfrom
Bahtya:fix/bool-inverse-panic

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 5, 2026

Problem

When FlagStringer returns a string without a tab character, strings.Index(out, "\t") returns -1. Then out[i:] panics with index out of range [-1].

Solution

Add guard: if no tab found, return the string as-is.

if i == -1 {
    return out
}

Fixes #2303

@Bahtya Bahtya requested a review from a team as a code owner April 5, 2026 02:18
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
@Bahtya Bahtya closed this by deleting the head repository Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BoolWithInverseFlag.String() panics when FlagStringer returns string without tab

2 participants