Repository navigation
Conversation
) Keys are lowercased before being split on the key delimiter, but the delimiter itself was stored raw. With an uppercase delimiter (e.g. KeyDelimiter("<SEPARATOR>")), the lowercased key never contains the delimiter, so strings.Split yields a single flat element and nested values are silently lost. Normalize the delimiter to lowercase at construction in the KeyDelimiter option. All 25 use-sites are fixed by normalizing at the single entry point. The default delimiter "." is already lowercase and unaffected. Closes spf13#2069. Same fix as never-merged PR spf13#2084. Add regression test TestKeyDelimiterCase verifying nested YAML values resolve correctly with an uppercase delimiter (fails pre-fix, passes post-fix).
|
|
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.
Overview:
Normalize the key delimiter to lowercase at construction so that nested key lookups work when the delimiter contains uppercase letters. This is a one-line fix in the
KeyDelimiteroption.What problem does it solve?:
When a user configures a key delimiter containing uppercase letters (e.g.
KeyDelimiter("<SEPARATOR>")), nested key lookups silently fail. This is because all keys are lowercased before being split on the delimiter (strings.ToLower(key)atviper.go:716, thenstrings.Split(lcaseKey, v.keyDelim)atviper.go:725/1198/1209), but the delimiter itself is stored raw. A lowercased key likeseverity<separator>foonever contains the uppercase<SEPARATOR>, sostrings.Splityields a single flat element and the nested value is lost.Closes #2069. This is the same fix as the never-merged PR #2084.
Special notes for a reviewer:
KeyDelimiteroption (v.keyDelim = strings.ToLower(d)).keyDelim(Get/Set/SetDefault/AllKeys/AllSettings/searchIndexableWithPathPrefixes/etc.) are fixed by normalizing at the single entry point."."is already lowercase and unaffected.Sub()copies the already-normalized value, so no change needed there.TestKeyDelimiterCaseverifies that a nested YAML value is correctly resolved with an uppercase delimiter (fails pre-fix, passes post-fix).