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

Add configuration to disable variable substitution #113

Open
phillipleblanc opened this issue Jul 29, 2024 · 7 comments
Open

Add configuration to disable variable substitution #113

phillipleblanc opened this issue Jul 29, 2024 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@phillipleblanc
Copy link

The variable substitution feature of dotenv means that any environment variables that should have the $ in them are removed.

I would like a way to disable this functionality, since my project doesn't need it and it causes surprise among users when they discover their environment variables aren't working as expected.

@aidenfarley
Copy link

Do you have a specific way in mind to disable substitution?

@phillipleblanc
Copy link
Author

phillipleblanc commented Jul 29, 2024

Perhaps adding a new DotEnvBuilder which accepts a parameter with_variable_substution(bool) which can be used to customize how the environment is loaded. The existing methods could all just call DotEnvBuilder with the different parameters that make them different.

i.e.

DotEnvBuilder::new().with_variable_substution(false).load()?

or

DotEnvBuilder::new().from_filename("my_filename").load()?

The existing methods would still work:
dotenvy::from_filename -> would just be DotEnvBuilder::new().from_filename("my_filename").load()? under the hood.

@sonro
Copy link
Collaborator

sonro commented Jul 29, 2024

We are currently redesigning the API to allow for more extensible configuration. A builder pattern is likely to be part of it.

In the meantime, variable substitution is the same as in the vast majority of other "dotenv" implementations. You can escape it with a backslash or strong single quotes—the same as most shells' handling of environment variables.

KEY_ONE='$VAL'
ANOTHER_KEY=\$VAL

Both KEY_ONE and ANOTHER_KEY would be set to '$VAL'.

@allan2
Copy link
Owner

allan2 commented Jul 30, 2024

@phillipleblanc good idea. This will be supported in the next release.

@aidenfarley
Copy link

@allan2 Is there a PR in progress yet for the new API change, or just the discussion in #39. How can I contribute?

@allan2
Copy link
Owner

allan2 commented Jul 31, 2024

Hi @aidenfarley, I am working on a design locally. I haven't opened a PR yet, but it will come before the Rust 2024 edition. Stay tuned.

@allan2
Copy link
Owner

allan2 commented Sep 4, 2024

Hello, there is a new API on the v0.16 branch. PRs are welcome to that branch. I would suggest EnvLoader::substitution(true).

@allan2 allan2 added the good first issue Good for newcomers label Sep 4, 2024
@allan2 allan2 added the enhancement New feature or request label Sep 4, 2024
@allan2 allan2 added this to the v0.16 milestone Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants