config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Fix uppercase lowercase isses

Open YounessBird opened this issue 2 years ago • 3 comments

fix #340

YounessBird avatar Jun 30 '22 11:06 YounessBird

I have chosen the first approach, which is to use lowercase keys which will make the crate case insensitive, this will allow the user to use uppercase or lowercase keys but internally the keys can be easily matched and overridden since they are all lowercase. As of the caveat I mentioned here I managed to fix it by matching the fields and the keys for lowercase in the deserialization phase.

YounessBird avatar Jun 30 '22 11:06 YounessBird

Thanks. I will add your suggestion to the chore list 😄

YounessBird avatar Jul 03 '22 23:07 YounessBird

Done and ready for a review.

YounessBird avatar Jul 05 '22 10:07 YounessBird

There is still a bug (as of 0.13.3). Consider this:

let conf: HashMap<String, String> = Config::builder()
    .add_source(File::with_name(name))
    .add_source(Environment::with_prefix(prefix))
    .build()?
    .try_deserialize()?;

File:

KEY = "value1"

Env:

PREFIX_KEY=value2

Then: Current behavior: conf has 2 keys: KEY & key with values value1 & value2 Expected behavior: conf has 1 key: KEY with value value2

utkarshgupta137 avatar Jan 02 '23 09:01 utkarshgupta137