Skip to content

key delimiter can't be uppercase #2069

@djehuti

Description

@djehuti

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.
  • I have checked the troubleshooting guide for my problem, without success.

Viper Version

1.18.2

Go Version

1.24.6

Config Source

Files

Format

YAML

Repl.it link

No response

Code reproducing the issue

v := viper.NewWithOptions(viper.KeyDelimiter("<SEPARATOR>"))

Expected Behavior

For map values, they will come in blank because of this line:

viper/viper.go

Line 1153 in 0525738

path = strings.Split(lcaseKey, v.keyDelim)

This code:

		path   = strings.Split(lcaseKey, v.keyDelim)

should be

		path   = strings.Split(lcaseKey, strings.ToLower(v.keyDelim)

I don't think I can open a PR against this repo, or I would just send one. Hopefully this is a simple enough patch to describe here.

Actual Behavior

When I read the config file, and I read this:

severity:
  foo: warning

I don't get a value for severity from v.Unmarshal, because the split is splitting a lowercased string on a possibly-upper-case keyDelim.

See fix above: call strings.ToLower() on the v.keyDelim before splitting on it.

Steps To Reproduce

No response

Additional Information

I need to support map-valued config keys whose subkeys contain dots even though that map is flat.

My workaround is that I'm using · (U+00B7) as a keyDelim instead of <SEPARATOR>. Because my map is flat, I just need something that nobody will ever actually want to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions