Skip to content

Initialize the target map when a StringToString flag has a nil default - #506

Merged
tomasaschan merged 2 commits into
spf13:masterfrom
nikolauspschuetz:fix-string-to-string-nil-default-panic
Sep 6, 2026
Merged

Initialize the target map when a StringToString flag has a nil default#506
tomasaschan merged 2 commits into
spf13:masterfrom
nikolauspschuetz:fix-string-to-string-nil-default-panic

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

A StringToString flag declared with a nil default map panics with assignment to entry in nil map the first time it's set — stringToStringValue.Set writes into *s.value without allocating it.

This allocates the map when it's nil before merging the parsed values, and adds a nil-default regression test.

Verified: the new test panics on current code and passes with the fix; the full pflag suite stays green.

Developed with AI assistance (Claude Code); I directed, reviewed, and verified it locally.

stringToStringValue.Set wrote into *s.value directly, so a StringToString
flag declared with a nil default map panicked with "assignment to entry
in nil map" the first time it was set. Allocate the map when it is nil
before merging parsed values, and cover the nil-default case in a test.
@CLAassistant

CLAassistant commented Aug 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review August 26, 2026 19:56
@nikolauspschuetz

Copy link
Copy Markdown
Author

Lint here was the golangci-lint/Go 1.27 export-data breakage, not this change — merged master so #508 is in. Needs a workflow-run approval to go green.

@tomasaschan
tomasaschan merged commit 45c0ef7 into spf13:master Sep 6, 2026
8 checks passed
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.

3 participants