Conversation
MapBase.Set routes only the value through the configured value parser and writes the key into the dict raw, so StringConfig.TrimSpace reached one half of each pair. SliceBase has had this since urfave#2171.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What this PR does / why we need it:
StringConfig.TrimSpacereaches only half of each pair in a map flag.MapBase.Setroutes the value through the configured parser atflag_map_impl.go:84but writes the key into the dict raw at:87, so the key never sees the config:cmd.StringMap("m")["b"]misses on--m "a=1, b=2"because the stored key is" b".SliceBasehas routed every element through the parser since #2171;MapBaseis the one place aStringConfig-carrying string reaches storage without passing the config.Which issue(s) this PR fixes:
None filed. Follows #2171 and #2425, which fixed the value side of the same seam.
Release Notes
Verification
Base
9b981a0.flag_map_impl.gomd57031d44c5df33bcad660trim_enabledc3186d07ebtrim_enabledcaa059492ctrim_disabledThe two mutants fail on different subtests, so the test pins both that the key is trimmed under
TrimSpace: trueand that it is left alone underTrimSpace: false.make vet,make test,make v3diffandmake generateall clean;gofmt -l .empty; no exported API change and no godoc drift.make check-binary-sizeand thegfmrunexamples were not run here.One thing worth your call: reading the config in
Createwithany(c).(StringConfig)mirrors thereflect.TypeOf(t).Kind()approachSliceBasealready uses, but it is still a type assertion inside a generic. If you would rather thread it differently, the test and the behaviour survive either shape.StringMapFlagis currently the only map flag the library ships, so this does not affect any other element type.Disclosure: written with the help of Claude (an AI assistant). Every number above is from runs on my machine.