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 handling invalid collection items in configuration #97777

Merged

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Jan 31, 2024

#97558

In .NET 8.0, a breaking change was introduced through PR. This modification aimed to enable the recognition of empty or null collection items in configuration. However, it inadvertently led to the acceptance of invalid non-null or non-empty items as well. This fix addresses the issue both in the runtime binder and the source generator.

@ghost
Copy link

ghost commented Jan 31, 2024

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

Issue Details

#97558

In .NET 8.0, a breaking change was introduced through PR. This modification aimed to enable the recognition of empty or null collection items in configuration. However, it inadvertently led to the acceptance of invalid non-null or non-empty items as well. This fix addresses the issue both in the runtime binder and the source generator.

Author: tarekgh
Assignees: tarekgh
Labels:

area-Extensions-Configuration

Milestone: -

@tarekgh
Copy link
Member Author

tarekgh commented Jan 31, 2024

CC @Maximys @beppemarazzi @bbenameur

@tarekgh tarekgh added this to the 9.0.0 milestone Jan 31, 2024
@@ -119,6 +119,10 @@ namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration
{
foreach (IConfigurationSection section in configuration.GetChildren())
{
if (!string.IsNullOrEmpty(section.Value) && !section.GetChildren().GetEnumerator().MoveNext())
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this be generated using !section.GetChildren().Any() instead? It could theoretically avoid the enumerator allocation provided that the underlying enumerable implements ICollection<T>.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will need to add a dependency on System.Linq which comes with its own complication if the project not referencing it.

Copy link
Member

Choose a reason for hiding this comment

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

There are plenty of existing spots in this generated code that might benefit from Linq, or even this API: #83692

Not sure we should tackle introducing new dependencies to this code at this point for a regression bugfix. Instead we should think about minimizing this change and reducing risk as we'll likely want to backport it. Codebase refactoring can be captured in a separate issue.

Copy link
Member

Choose a reason for hiding this comment

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

It's not technically adding a dependency that wasn't there before though, right? All supported TFMs include System.Linq.

Copy link
Member Author

Choose a reason for hiding this comment

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

We'll address this in a different PR.

@Maximys
Copy link
Contributor

Maximys commented Feb 1, 2024

@tarekgh , my bad. Thanks for fix

@tarekgh
Copy link
Member Author

tarekgh commented Feb 1, 2024

@Maximys no worries. I tagged you only for awareness and if you have any feedback. Thanks for all help you have provided all the way.

@tarekgh tarekgh merged commit 0fff4ef into dotnet:main Feb 1, 2024
107 of 111 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants