Closed ReeceHumphreys closed 4 months ago
Actually, thinking about this a bit more, C# uses XML doc comments so the apostrophes should have escaping so this may not be a bug. Can someone confirm @pepone, @externl, @bernardnormier.
Yes, escaping is required in C# doc comments.
Actually '
doesn't need to be escaped in the summary
See for example:
And source
Actually ' doesn't need to be escaped in the summary
Does it need to be escaped anywhere?
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments
This page doesn't call them out as needing to be escaped, and it shows apostrophes appearing unescaped in <param>
tags, <value>
tags, <returns>
, and <example>
tags as well.
And to my knowledge, you don't need to escape single quotes in XML text content.
And to my knowledge, you don't need to escape single quotes in XML text content.
See: https://www.w3.org/TR/xml/#syntax
It seems that '
is only required for attributes delimited with single quotes '
. For text elements, only the characters &
and <
need to be escaped.
So I guess the next thing to check is do we ever use '
to delimit attributes.
I expect we probably don't, "
feels more standard to me, and should accomplish the same thing.
I don't see anywhere in slicec-cs
where we're outputting '
for attributes.
So it's probably safe to just never escape it.
Should we make our escaping function smarter? To support some way of passing in a context so we don't overescape? Right now it's just:
fn xml_escape(text: &str) -> String {
text.replace('&', "&")
.replace('<', "<")
.replace('>', ">")
.replace('\'', "'")
.replace('"', """)
}
I think you just need to remove .replace('\'', "'")
.
I agree that's definitely the easy fix.
I Just wanted to see if anyone wanted to advocate for adding a more complex fix, but that would only escape when absolutely necessary. I don't think it's worth it, but one could make an argument for it.
Description
Documentation comments for slice that contain apostrophes result in generated C# documentation comments with
'
instead of an apostrophe.Reproduction steps
Example Slice:
foo.slice
Generated code snippet:
foo.IceRpc.cs
Expected behavior
I would expect the generated output comment to look like:
Actual behavior
The apostrophe is being escaped.
Configuration
slicec-cs version: '0.4.0' (main branch) macOS 14.5 (23F79)
Additional information
No response