Skip to content

Commit

Permalink
fix: Fix formatting of preformatted XML docs
Browse files Browse the repository at this point in the history
This avoids double-escaping.
  • Loading branch information
jskeet committed Sep 1, 2022
1 parent 3db8cb0 commit 0c1e8f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ public void MultiLine()
[Fact]
public void Preformatted()
{
// Whitespace around " Line 2 " is delibrate, to test extra whitespace removal at end of lines only.
// Whitespace around " Line 2 " is deliberate, to test extra whitespace removal at end of lines only.
var s = XmlDocSplitter.Split(s_indent4, 40, TrivList(XmlDoc.SummaryPreFormatted(new[] { "Line 1", " Line 2 " }))).ToFullString();
Assert.Equal($" /// <summary>{s_nl} /// Line 1{s_nl} /// Line 2{s_nl} /// </summary>{s_nl}", s);
}

[Fact]
public void PreformattedWithAngleBrackets()
{
var summary = XmlDoc.SummaryPreFormatted(new[] { "Before <angles> after" });
var split = XmlDocSplitter.Split(s_indent4, 80, TrivList(summary)).ToFullString();
Assert.Equal($" /// <summary>{s_nl} /// Before &lt;angles&gt; after{s_nl} /// </summary>{s_nl}", split);
}
}
}
5 changes: 4 additions & 1 deletion Google.Api.Generator.Utils/Formatting/XmlDocSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ private IEnumerable<DocumentationCommentTriviaSyntax> SplitPreformatted(Document
{
if (node is XmlTextSyntax text)
{
yield return OneLine(XmlText(string.Join("", text.GetText().Lines).TrimEnd()));
// Create an XmlTextLiteral with exactly the value we've fetched. This avoids
// double-escaping < to &amp;lt; when it should just be &lt;
string value = string.Join("", text.GetText().Lines).TrimEnd();
yield return OneLine(XmlText(XmlTextLiteral(value, value)));
}
else
{
Expand Down

0 comments on commit 0c1e8f8

Please sign in to comment.