Skip to content

Improves handling of env prefixes containing __ - #65757

Merged
maryamariyan merged 1 commit into
dotnet:mainfrom
dhedey:fix/65756-env-config-prefix
Mar 23, 2022
Merged

maryamariyan merged 1 commit into
dotnet:mainfrom
dhedey:fix/65756-env-config-prefix

Conversation

@dhedey

@dhedey dhedey commented Feb 23, 2022

Copy link
Copy Markdown
Contributor

This PR is intended to fix #65756.

Key changes:

  • By comparing normalized prefixes to normalized keys, both the un-altered and colon-normalized prefixes match environment variables in either the __ or colon formats.
  • There is a change of behaviour that some environment variables which theoretically didn't match the filter before may now match the filter, but I don't expect this to be an issue in practice (I very much doubt anyone configures variables with both a : and __ prefix, and relies on the fact that these don't match)
  • I was very careful to ensure other existing behaviour is maintained, to avoid any potential issues such as Breaking change in environment variable configuration prefix support in dotnet 6 #61577 or any changes of behaviour with the special case connection string matching.

The change includes minor refactors to the EnvironmentVariablesConfigurationProvider to make the code easier to follow and reduce the likelihood of future regressions. Test naming has been made clearer, and a comprehensive test has been added.

If approved for merge into 6.0.x, this would fix the breaking change in 6.0.2 documented in #65756.

Both the un-altered and colon-normalized prefixes now match
environment variables in either the __ or colon formats.

The change includes minor refactors to
the EnvironmentVariablesConfigurationProvider
to make the code easier to follow and reduce the likelihood
of future regressions.

Test naming has been made clearer, and a comprehensive test
has been added.

Fix dotnet#65756
@ghost ghost added area-Extensions-Configuration community-contribution Indicates that the PR has been added by a community member labels Feb 23, 2022
@ghost

ghost commented Feb 23, 2022

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

This PR is intended to fix #65756.

Key changes:

  • By comparing normalized prefixes to normalized keys, both the un-altered and colon-normalized prefixes match environment variables in either the __ or colon formats.
  • There is a change of behaviour that some environment variables which theoretically didn't match the filter before may now match the filter, but I don't expect this to be an issue in practice (I very much doubt anyone configures variables with both a : and __ prefix, and relies on the fact that these don't match)
  • I was very careful to ensure other existing behaviour is maintained, to avoid any potential issues such as Breaking change in environment variable configuration prefix support in dotnet 6 #61577 or any changes of behaviour with the special case connection string matching.

The change includes minor refactors to the EnvironmentVariablesConfigurationProvider to make the code easier to follow and reduce the likelihood of future regressions. Test naming has been made clearer, and a comprehensive test has been added.

If approved for merge into 6.0.x, this would fix the breaking change in 6.0.2 documented in #65756.

Author: dhedey
Assignees: -
Labels:

area-Extensions-Configuration

Milestone: -

@dnfadmin

dnfadmin commented Feb 23, 2022 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@maryamariyan maryamariyan added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Mar 1, 2022
@ghost ghost added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Mar 1, 2022
@ghost

ghost commented Mar 1, 2022 •

Copy link
Copy Markdown

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@maryamariyan maryamariyan self-assigned this Mar 15, 2022
@maryamariyan

maryamariyan commented Mar 15, 2022 •

Copy link
Copy Markdown
Contributor

Thanks for the PR @dhedey.

Does the PR also have a test to cover the regression use case and showing that is not broken with the changes in this PR?

@dhedey

dhedey commented Mar 16, 2022

Copy link
Copy Markdown
Contributor Author

Hi @maryamariyan - thanks for taking a look for me :)

Yes, as it happens, this is already covered by the test that was written as part of #62819 - in particular AddEnvironmentVariables_Bind_PrefixShouldNormalize from this PR has been renamed to AddEnvironmentVariablesUsingNormalizedPrefix_Bind_PrefixMatches - but the test body is identical:

                Environment.SetEnvironmentVariable(EnvironmentVariable, "myFooValue"); // EnvironmentVariable is "Microsoft__Extensions__Configuration__EnvironmentVariables__Test__Foo"
                var configuration = new ConfigurationBuilder()
                    .AddEnvironmentVariables("Microsoft:Extensions:Configuration:EnvironmentVariables:Test:")
                    .Build();

                var settingsWithFoo = new SettingsWithFoo();
                configuration.Bind(settingsWithFoo);

                Assert.Equal("myFooValue", settingsWithFoo.Foo);

This checks that an environment variable written in "Linux" mode with __ can still match a prefix defined in "Windows / normalized" mode with ":", which captures exactly the source of the original regression raised in #61577

@maryamariyan
maryamariyan merged commit 9cd49ff into dotnet:main Mar 23, 2022
@maryamariyan

Copy link
Copy Markdown
Contributor

Thanks @dhedey for the contribution! This should make it to preview 4.
One note of observation for next time, the PR review could be easier if the rename/refactors were separated into their own commit. :)

@dhedey

dhedey commented Mar 23, 2022

Copy link
Copy Markdown
Contributor Author

Thanks @dhedey for the contribution! This should make it to preview 4. One note of observation for next time, the PR review could be easier if the rename/refactors were separated into their own commit. :)

Many thanks @maryamariyan. Understood - will be sure to separate my commits better next time!

@dhedey
dhedey deleted the fix/65756-env-config-prefix branch March 29, 2022 10:18
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
Both the un-altered and colon-normalized prefixes now match
environment variables in either the __ or colon formats.

The change includes minor refactors to
the EnvironmentVariablesConfigurationProvider
to make the code easier to follow and reduce the likelihood
of future regressions.

Test naming has been made clearer, and a comprehensive test
has been added.

Fix dotnet#65756
@ghost ghost locked as resolved and limited conversation to collaborators Apr 28, 2022
@ericstj ericstj added this to the 7.0.0 milestone Sep 15, 2022
@ericstj

ericstj commented Oct 4, 2022

Copy link
Copy Markdown
Member

@maryamariyan did you create a breaking change document for this?

@gewarren

Copy link
Copy Markdown
Contributor

@ericstj Yes she did - dotnet/docs#31490.

@ericstj

ericstj commented Oct 12, 2022

Copy link
Copy Markdown
Member

Thank you @gewarren. @maryamariyan can you please follow the steps here #65757 (comment)?

@maryamariyan

Copy link
Copy Markdown
Contributor

Done. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-Configuration breaking-change Issue or PR that represents a breaking API or functional change over a previous release. community-contribution Indicates that the PR has been added by a community member needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing environment variable configuration prefix behaviour reintroduced in 6.0.2

6 participants