[release/7.0] Fix incorrect "illegal XML comment chars" check & add regression tests #74823
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #74787 to release/7.0. Resolves #74752.
Customer Impact
As of 7.0,
XmlTextWriter
can no longer write XML comments which begin with a hyphen ('-'
) character. This was due to an incorrect optimization in System.Xml introduced in the 7.0 timeframe. We should forbid hyphens at the end of the string, not at the beginning.This is a regression from 6.0 and Full Framework. Partner teams like F# have had to work around this in their own code bases since it's affecting some of their build scenarios.
Workaround for customers is that if they call
XmlWriter.WriteComment
, they ensure that the argument does not begin with a hyphen. I don't imagine a hyphened prefix is all that common, but as above, the F# team did run into it. Fortunately they controlled the input and had the ability to strip the hyphen. Other customers might not be able to exercise such control.Testing
Tested through ad hoc sample applications and increasing unit test coverage. I also compared the outputs against core3.1, 6.0, and netfx481 to validate that we're not morphing the data unexpectedly.
I also went through and double-checked the original PR which introduced the regression, looking for other places where we may have introduced a similar error. That investigation turned up only a single additional suspicious call site, but that call site was already addressed by a previous PR before RC1 snap. The call site addressed by this PR is the only remaining call site.
Risk
Low risk. This changes a single line of code, and I've improved unit test coverage both as a regression test and to ensure that we didn't inadvertently block other legitimate scenarios.
No packaging impact.