thesimj / envyaml

Simple YAML configuration file parser
MIT License
78 stars 21 forks source link

lowercase environment will cause error #47

Open fengxiao2019 opened 1 year ago

fengxiao2019 commented 1 year ago

Describe the bug if the environment variable name contains lower letters, the config file contains use this environment variable, this package cannot find the related environment.

To Reproduce Steps to reproduce the behavior: step1: set the environment variable name: api-key step2: set the environment variable value: hellow-world step3: sample config: sample.yaml

proxy:
    api-key: $api-key

in the strict mode, this package will raise error.

Desktop (please complete the following information):

barneygale commented 1 year ago

Environment variables are case-insensitive on Windows, and so os.environ isn't a simple dictionary. Docs:

On Windows, the keys are converted to uppercase. This also applies when getting, setting, or deleting an item.

The problem here is that EnvYAML.__cfg flattens the environment to a regular dict, which loses the case-insensitive lookup.

One solution might be to use a collections.ChainMap to wrap the os.environ object.

barneygale commented 1 year ago

PR: https://github.com/thesimj/envyaml/pull/49

hotnsoursoup commented 2 months ago

Issue still found with all lowercase characters for environment variable in 1.10.211231. Verified terminal can see environment in powershell terminal in vscode.