Escape cref value in generated <see> doc comments#4566
Escape cref value in generated <see> doc comments#4566pepone wants to merge 3 commits intoicerpc:mainfrom
Conversation
cs::type can contain XML-special characters (e.g. generics like List<int>), which would produce malformed XML doc comments when spliced raw into a cref attribute.
There was a problem hiding this comment.
Pull request overview
Updates the Slice-to-C# doc comment formatter to properly XML-escape generated <see cref="..."/> attribute values, preventing malformed XML when entity names/namespaces contain XML-special characters (Fix #4494).
Changes:
- XML-escapes the
crefattribute value when emitting inline<see ... />links for resolved comment links.
InsertCreativityHere
left a comment
There was a problem hiding this comment.
I don't think this is correct.
The string that we generate here is fully contained within double quotes:
<see cref="..." /> So where's the need to escape XML characters?
The only way to break the XML is to put a literal \" character in their cs::type or cs::identifier, which means they've gone insane. Not something we should protect against :)
Assuming sanity, there's no reason for &, <, > or " to ever appear in cs::identifier.
I don't think that & or " can ever validly be part of a type-name in C#, can they?
< and > can appear in cs::type for a generic type, but according to the docs, the correct behavior here isn't to XML escape them, it's to replace them with { and }:
Seems XML is even more complicated than this. For an attribute value, |
|
If you search for So, instead of XML escaping, we should be ignoring |
I guess this is not a general XML rule, but a C# documentation one, isn't it? |
For inline @link to a TypeAlias, emit <see cref="MappedType"/> when the mapped type is non-generic, or <c>MappedType</c> (XML-escaped) when it is generic — closed generics like IList<string> have no valid C# cref form, so a clickable link isn't possible. For @see, emit <seealso/> only for non-generic mapped types and skip generic ones. Add typealias coverage to DocumentationTests.slice for non-generic, sequence, dictionary, and result mappings.
|
Replaced by #4573 |
Fix #4494