-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnmarshalKey normalizes all map keys to lower case #373
Comments
This doesn't seem to be documented anywhere but internally, Viper lowercases all keys which is weird: Line 1303 in d9cca5e
This goes against the YAML, TOML, and JSON specs where keys are case sensitive. |
I will request viper authors to comment. |
@spf13 any comment? |
Just came across this today. Is there an option or workaround to disable this behaviour? |
YAML, TOML, and JSON dictate keys to be case-sensitive. Viper's default behaviour of lowercasing the keys for key insensitivity is incompatible with these standards and has the side effect of making it difficult for use cases such as case sensitive API credentials in configuration. For eg: MyApiKey=MySecret (in TOML). See spf13#131, spf13#260, spf13#293, spf13#371, spf13#373 This commit adds a global function `viper.SetKeyCaseSensitivity()` that enables this behaviour to be turned off, after which, all keys, irrespective of nesting, retain their cases. This respects all configuration operations including getting, setting, and merging.
YAML, TOML, and JSON dictate keys to be case-sensitive. Viper's default behaviour of lowercasing the keys for key insensitivity is incompatible with these standards and has the side effect of making it difficult for use cases such as case sensitive API credentials in configuration. For eg: MyApiKey=MySecret (in TOML). See spf13#131, spf13#260, spf13#293, spf13#371, spf13#373 This commit adds a global function `viper.SetKeyCaseSensitivity()` that enables this behaviour to be turned off, after which, all keys, irrespective of nesting, retain their cases. This respects all configuration operations including getting, setting, and merging.
YAML, TOML, and JSON dictate keys to be case-sensitive. Viper's default behaviour of lowercasing the keys for key insensitivity is incompatible with these standards and has the side effect of making it difficult for use cases such as case sensitive API credentials in configuration. For eg: MyApiKey=MySecret (in TOML). See spf13#131, spf13#260, spf13#293, spf13#371, spf13#373 This commit adds a global function `viper.SetKeysCaseSensitive()` that enables this behaviour to be turned off, after which, all keys, irrespective of nesting, retain their cases. This respects all configuration operations including getting, setting, and merging.
…nverted to lower case
#666 fixes it |
This issues is still there |
@codemodify #635 has been pending for almost a year and should give you better context on the state of this issue. |
want a fix for this issue as well :( |
@codemodify @ackratos this is not an easy fix as it goes directly against core Viper principles and goals. I'm working on it, but please keep in mind this is an open source project with a lot of users. A major change like this is not easy to pull in. |
Thank you, completely understand, will it be ok to have this highlighted on the front page that can be used for making decisions when picking up tools ? The reason for that is because when you are half way through it is hard to drift away when you understand the limits |
I've just hit this too, and it's most unexpected. I'm demarshalling a struct that contains a map. The struct fields demarshall fine but the map keys all come out lower case, which is unexpected. |
I had to make the map into a slice to work around this, making the key a field value of the slice element. Lucky I have control of the data structure. But still want to see viper handling case-sensitive map keys locally. |
Still no development on this issue I guess? |
@farukarakaya Feel free to use https://github.com/lnashier/viper it does not normalize key to lower case. |
Tracking the issue in #1014 |
Still seems to be an issue and it took me awhile to find the issue. |
still a issue |
still an issue |
1 similar comment
still an issue |
still an issue, can we config this as option |
I just want to add that I am running in to this. This issue has been open for almost 7 years and there is still no option to disable this behavior? Why? |
I imagine 'breaking change' ..aka 'we fucked up but now everyone works around it, if we fix it it breaks all those workarounds.' It's pig-headedness and they should just pull the bandaid off. |
It is still an issue |
This solves problem with map structure described -> spf13/viper#373 that caused issue in Greenmask #76 We need to keep the original keys in the map without lowercasing. To overcome this problem we need use default yaml and json parsers avoiding vaiper or mapstructure usage
This is still an issue. Any updates on a fix? |
myMap
has all lower-cased keys.Can somebody comment if it is expected or is it a bug ?
The text was updated successfully, but these errors were encountered: