Skip to content

feat: parse map[string][]string with key/value separators (#398) - #453

Open
SkipGip wants to merge 1 commit into
caarlos0:mainfrom
SkipGip:cursor/map-string-slice-4141
Open

SkipGip wants to merge 1 commit into
caarlos0:mainfrom
SkipGip:cursor/map-string-slice-4141

Conversation

@SkipGip

@SkipGip SkipGip commented Oct 27, 2026

Copy link
Copy Markdown

Summary

Test plan

  • go test ./...
  • go test -race ./...
  • Table-driven cases for multi-value keys and custom separators

Closes #398

Related: volunteering on #407

Accept map values that are slices using the existing envSeparator and
envKeyValSeparator tags. Duplicate keys append an element instead of
replacing the slice. A FuncMap parser registered for the slice type
keeps the previous last-value-wins behavior.

Co-authored-by: SkinGap <SkipGip@users.noreply.github.com>

@caarlos0 caarlos0 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

One correctness issue needs correction. Verification limits: this head has no reported CI checks or commit statuses. No local builds or tests were run; this review used static analysis and both required independent checks.

– Copilot, on behalf of Carlos

Comment thread env.go
Comment on lines +823 to +825
elemParserFunc, ok := funcMap[sliceElemType]
if !ok {
elemParserFunc, ok = defaultBuiltInParsers[sliceElemType.Kind()]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[P2] Honor TextUnmarshaler before selecting the element parser

The new slice-valued map path bypasses element UnmarshalText methods. With the existing LogLevel type from env_test.go, map[string][]LogLevel and input foo:debug select strconv.ParseInt because the underlying kind is int8, so a valid debug value fails. Conversely, foo:7 succeeds even though LogLevel.UnmarshalText rejects it. Ordinary []LogLevel fields honor this method first (handleSlice), and the supported-types documentation includes TextUnmarshaler. Apply the same precedence here before the FuncMap/built-in fallback, while retaining whole-slice custom-parser behavior. Add a regression test for duplicate debug/info values and rejection of numeric 7.

– Copilot, on behalf of Carlos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native support for map[string][]string?

3 participants