Skip to content
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

Fix uppercase lowercase isses #354

Merged

Conversation

YounessBird
Copy link
Contributor

fix #340

@YounessBird
Copy link
Contributor Author

YounessBird commented Jun 30, 2022

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 YounessBird force-pushed the fix-uppercase-lowercase-isses branch 2 times, most recently from bcb1966 to da78382 Compare June 30, 2022 12:16
Copy link

@pictographer pictographer left a comment

Choose a reason for hiding this comment

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

Looks good.

One suggestion. Mention that keys are case insensitive in the docs.

@YounessBird
Copy link
Contributor Author

YounessBird commented Jul 3, 2022

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

@YounessBird YounessBird force-pushed the fix-uppercase-lowercase-isses branch 14 times, most recently from 7cab5d6 to 0a2e8eb Compare July 5, 2022 10:29
@YounessBird
Copy link
Contributor Author

Done and ready for a review.

Copy link
Collaborator

@matthiasbeyer matthiasbeyer left a comment

Choose a reason for hiding this comment

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

So first of all, thanks for working on this. This is important to get right.

I have some remarks, nothing too critical.

Still, I am not sure whether this is the right way to go. Converting all things to lowercase seems ... I don't know to be honest.

I am willing to merge this (modulo some things that have to be cleared), if we do not find another way... that said, when (if) we re-do the crate (#321) we should get it right from the get-go and support case sensitivity as well as insensitivity (let the user decide). But that's of course for another day, I guess.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/config.rs Show resolved Hide resolved
src/de.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
tests/Settings.json Outdated Show resolved Hide resolved
tests/Settings.json5 Outdated Show resolved Hide resolved
tests/Settings.yaml Outdated Show resolved Hide resolved
@YounessBird YounessBird force-pushed the fix-uppercase-lowercase-isses branch 2 times, most recently from 1b03bf4 to 0bb4c7a Compare July 14, 2022 08:50
@YounessBird YounessBird force-pushed the fix-uppercase-lowercase-isses branch from 7227e97 to b2dfb93 Compare July 14, 2022 09:28
Copy link
Collaborator

@matthiasbeyer matthiasbeyer left a comment

Choose a reason for hiding this comment

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

This was laying around way too long. I'm gonna merge this now, sorry for me taking so long!

@matthiasbeyer matthiasbeyer merged commit 0d58da2 into mehcode:master Sep 17, 2022
@utkarshgupta137
Copy link

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

wfchandler pushed a commit to wfchandler/jj that referenced this pull request Feb 11, 2024
Update `config` to the latest minor version.

The latest version of `config` adds more detailed error information that
require updates to snapshot tests. More significantly, environment
config variables are no longer case-sensitive[1]. Internally they are
down-cased, so we must adjust `test_command_args` to set lowercase
environment variables.

In addition, the newly added `config::Value::origin()` method exposes
the path of config files.

[1] mehcode/config-rs#354
wfchandler pushed a commit to wfchandler/jj that referenced this pull request Feb 12, 2024
Update `config` to the latest minor version.

The latest version of `config` adds more detailed error information and
platform-specific file paths that require updates to snapshot tests.
More significantly, environment config variables are no longer
case-sensitive[1]. Internally they are down-cased, so we must adjust
`test_command_args` to set lowercase environment variables.

In addition, the newly added `config::Value::origin()` method exposes
the path of config files.

[1] mehcode/config-rs#354
wfchandler pushed a commit to wfchandler/jj that referenced this pull request Feb 13, 2024
Update `config` to the latest minor version.

The latest version of `config` adds more detailed error information and
platform-specific file paths that require updates to snapshot tests.
More significantly, environment config variables are no longer
case-sensitive[1]. Internally they are down-cased, so we must adjust
`test_command_args` to set lowercase environment variables.

In addition, the newly added `config::Value::origin()` method exposes
the path of config files.

[1] mehcode/config-rs#354
wfchandler pushed a commit to wfchandler/jj that referenced this pull request Feb 13, 2024
Update `config` to the latest minor version.

The latest version of `config` adds more detailed error information and
platform-specific file paths that require updates to snapshot tests.
More significantly, environment config variables are no longer
case-sensitive[1]. Internally they are down-cased, so we must adjust
`test_command_args` to set lowercase environment variables.

In addition, the newly added `config::Value::origin()` method exposes
the path of config files.

[1] mehcode/config-rs#354
wfchandler pushed a commit to wfchandler/jj that referenced this pull request Feb 13, 2024
Update `config` to the latest minor version.

The latest version of `config` adds more detailed error information and
platform-specific file paths that require updates to snapshot tests.
More significantly, environment config variables are no longer
case-sensitive[1]. Internally they are down-cased, so we must adjust
`test_command_args` to set lowercase environment variables.

In addition, the newly added `config::Value::origin()` method exposes
the path of config files.

[1] mehcode/config-rs#354
primeos-work added a commit to primeos-work/butido that referenced this pull request Feb 29, 2024
This reverts commit 2ec9497.

We do unfortunately have to downgrade since `config 0.14.0` [0] converts
all configuration keys to lowercase but some of our configuration keys,
e.g. the environment variables, are case sensitive.
More details are in the relevant upstream PR [1] that made the crate
case insensitive by converting all the keys to lowercase "internally"
and a new issue discussing this change/regression [2].
Unfortunately this wasn't really mentioned as a breaking change in the
upstream config-rs changelog so I missed it.
This fixes such errors:
```
Error: build command failed

Caused by:
    0: Checking allowed variable names
    1: Checking allowed variables for package tree 1.8.0
    2: Environment variable name not allowed: additional_make_flags
```

I didn't notice this regression at first as I relied on the tests but
they don't catch such errors yet. I'll try to add a test case for this
error and check the environment variables defined in `pkg.toml` files
during the loading of the repository (should yield better error messages
and we do want to verify **all** packages and during the loading of the
repository ("evaluation")).

[0]: https://github.com/mehcode/config-rs/blob/0.14.0/CHANGELOG.md#0140---2024-02-01
[1]: mehcode/config-rs#354
[2]: mehcode/config-rs#531
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Environment variable names are converted to lower case
4 participants