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

Interpolation stops working with SetEnvVars == false #92

Open
Philipp-Binder opened this issue Jan 13, 2024 · 3 comments
Open

Interpolation stops working with SetEnvVars == false #92

Philipp-Binder opened this issue Jan 13, 2024 · 3 comments

Comments

@Philipp-Binder
Copy link
Contributor

Interpolation is not properly working without SetEnvVars.

TestCase to show that:
Add LoadOptions.NoEnvVars() in EnvConfigurationTests-->AddSourceToBuilderAndParseInterpolatedTest:

this.configuration = new ConfigurationBuilder()
                .AddDotNetEnv("./.env_embedded", LoadOptions.NoEnvVars())
                .Build();

The test fails now with the first interpolation as shown here:
grafik

Originally posted by @Philipp-Binder in #90 (comment)

@Philipp-Binder
Copy link
Contributor Author

I already investigated some ways how to solve that, but wanted to add some other partially related fixes first.

Target will be to make the Parsers-class more independent by extracting the actual interpolation ==> Parser returns a non-evaluated value, and a separate "Interpolation-Class" will do the interpolation afterwards.
And of course while doing this trying to have as less breaking changes as possible, optimal would be nothing at all.
At least the "higher level" functions and default behavior should not change at all, just the "Parser-Engine".

@rogusdev
Copy link
Collaborator

rogusdev commented Mar 2, 2024

As explained in #93 (comment) -- SetEnvVar = false 's entire job is to not set the values from .env files into the env, so if you use interpolation, you will only get those env vars that are actually in the env, not from the .env file. This is behaving exactly as it should.

Does that address your concern?

@Philipp-Binder
Copy link
Contributor Author

I really do not understand, why with SetEnvVar == false we should have a different behavior of Interpolation.

Example:

  • EnvVar: T1=EnvValue
  • DotEnvVar: T1=DotEnvValue
  • DotEnvVar: T2=$T1

SetEnvVar == true ==> T2=DotEnvValue
SetEnvVar == false ==> T2=EnvValue

Why should we get different resulting values here?
I do not see the reason for Interpolation only considering EnvVars. I would expect to have the same result in both cases.
Of course, the actual EnvVar should be set with SetEnvVar, but not without. But why should that affect Interpolation?

The inversion of usage (EnvVar first, then DotEnvVar in reading order) is affected by Clobber/NoClobber, but it shouldn' t be affected by SetEnvVar imho.

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

No branches or pull requests

2 participants