Skip to content

fix: preserve brackets in integer map keys - #509

Open
mehuljariwala wants to merge 1 commit into
spf13:masterfrom
mehuljariwala:fix/integer-map-bracket-keys
Open

fix: preserve brackets in integer map keys#509
mehuljariwala wants to merge 1 commit into
spf13:masterfrom
mehuljariwala:fix/integer-map-bracket-keys

Conversation

@mehuljariwala

Copy link
Copy Markdown

GetStringToInt and GetStringToInt64 strip every leading and trailing square bracket from the formatted map. This removes brackets that belong to the first key: parsing --map=[key]=42 stores [key], but the getter returns key].

Remove only the single surrounding pair emitted by String(). Add table-driven regressions for bracketed keys, repeated opening brackets, a leading closing bracket, a brackets-only key, and an ordinary key. Each case checks the getter against the bound flag value.

Both getters fail the new bracket cases before the fix. Afterward, the full go test -race ./..., go vet ./..., and golangci-lint run pass on Go 1.27.1 (macOS arm64). Changes use APIs available under the project's Go 1.12 baseline.

Related to #413, but limited to the integer-valued map getters; the existing StringToString PRs are unaffected. Prepared with OpenAI Codex assistance, with the regression and validation commands executed locally.

@CLAassistant

CLAassistant commented Sep 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tomasaschan tomasaschan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

This seems like it might affect the handling of the value of the flag too - is it worth adding a few test cases to the table to show what the behavior is when a value ends with a bracket?

It seems likely to me that behavior is either unchanged, or fixed, by this PR, and making the behavior explicitly test covered makes it easier to reason about whether it's correct.

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