-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 support for repeated XML elements without a name attribute #43722
Conversation
This commit adds support in Microsoft.Extensions.Configuration.Xml for repeated XML elements without requiring a Name attribute. This solves a particularly subtle bug when configuring Serilog from an XML configuration source. For a full description, see dotnet#36541 The original implementation of the XmlStreamConfigurationProvider has been modified to do the following: - Maintain a stack of encountered XML elements while traversing the XML source. This is needed to detect siblings. - When siblings are detected, automatically append an index to the generated configuration keys. This makes it work exactly the same as the JSON configuration provider with JSON arrays. Tests are updated to reflect the new behavior: - Tests that verified an exception occurs when entering duplicate keys have been removed. Duplicate keys are supported now. - Add tests that verify duplicate keys result in the correct configuration keys, with all the lower/upper case variants and with support for the special "Name" attribute handling.
Tagging subscribers to this area: @maryamariyan |
I could use a little help with the failing build, I don't see how it's related to my changes. |
The failing build
is tracked by #43389 |
Thanks @amoerie for porting over this change to dotnet/runtime. We'll need to do a full review on the changes as it seems like there is a considerable change being introduced. Also adding @HaoK to this PR. Do you have any major hesitations on this kind of enhancement getting introduced into extensions configuration or it sounds good to you? |
I just want to add a little note to this sentence: the internal changes are indeed considerable, but the external compatibility has not been broken. I did not modify any existing tests (except for 2 tests that verified duplicate keys are not supported - now they are) and only added tests to verify the new supported behavior. In any case, I'm very interested to hear your feedback on my code. |
src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlStreamConfigurationProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Configuration.Xml/tests/ConfigurationProviderXmlTest.cs
Show resolved
Hide resolved
This ensures that, at the very least, it doesn't crash Correct behavior is covered by other tests
I don't have any particular concerns, other than the general one around accidental breaking changes. This behavior in particular has been asked for frequently, and it was always near the top of the list of PRs we were considering, so I think its a good candidate to be worth the risk. |
One thing worth mentioning is that this change appears only to be made in the XmlStreamProvider, it would be strange for there to be a big behavior difference between the stream and file providers? |
Are you saying there's other config provider implementations for XML files somewhere? Could you point me to them? I was operating under the assumption that everything would use the classes that I modified. |
Small update: I went digging a little and found no other implementations for XML files. In fact, I am convinced now that XML files also simply pass through the XmlStreamConfigurationProvider. See this class: runtime/src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationProvider.cs Lines 8 to 29 in f3d84ca
If I'm overlooking anything (this is a huge repo) please let me know and I'll make as many additions as necessary. |
/azp run runtime |
Commenter does not have sufficient privileges for PR 43722 in repo dotnet/runtime |
/azp run runtime |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks @maryamariyan Perhaps the PR guide could use an update, because I didn't see any option aside from pushing more commits or closing and reopening this PR. |
I'll close and reopen this PR to avoid merge commits. |
@amoerie how about the "rerun all checks" tab? |
I believe that is because that is not available for contributors, only for collaborators. I believe write permissions are needed in order to use /azp run... and to see the rerun buttons on the checks tab. |
We have three file providers, and XmlConfigurationProvider is one of them, the other two are JsonConfigurationProvider and IniConfigurationProvider. If I understood correctly @HaoK recommended if we are going to accept this breaking change in behavior that should also be done for the other two. |
Actually I wasn't talking about the other types of provider, I was referring to the old XmlConfigurationProvider, but indeed its just routing calls through the same code path so we should be good. |
I've recreated my pull request here: #44608 This cleans up the commit history (i've squashed my commits into one) and properly retries the CI. |
Fixes #36541
Fixes #36561
This pull request adds support in Microsoft.Extensions.Configuration.Xml for repeated XML elements without requiring a Name attribute.
This solves a particularly subtle bug when configuring Serilog from an XML configuration source. For a full description, see #36541
The original implementation of the XmlStreamConfigurationProvider has been modified to do the following:
Tests are updated to reflect the new behavior:
Thank you for your consideration.