Skip to content

Commit fdd7b60

Browse files
Escaping doccomments with xml characters
1 parent 9e94418 commit fdd7b60

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Octokit.GraphQL.Core.Generation.UnitTests/EntityGenerationTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,34 @@ public void Generates_Doc_Comments_For_Property()
16321632
CompareModel("Entity.cs", expected, result);
16331633
}
16341634

1635+
[Fact]
1636+
public void Generates_Doc_Comments_For_Property_With_XmlCharacters()
1637+
{
1638+
var expected = FormatMemberTemplate(@"/// <summary>
1639+
/// Testing if doc comments are generated &lt;http://localhost&gt;.
1640+
/// </summary>
1641+
public Other Foo => this.CreateProperty(x => x.Foo, Test.Other.Create);");
1642+
1643+
var model = new TypeModel
1644+
{
1645+
Name = "Entity",
1646+
Kind = TypeKind.Object,
1647+
Fields = new[]
1648+
{
1649+
new FieldModel
1650+
{
1651+
Name = "Foo",
1652+
Description = "Testing if doc comments are generated <http://localhost>.",
1653+
Type = TypeModel.Object("Other")
1654+
},
1655+
}
1656+
};
1657+
1658+
var result = CodeGenerator.Generate(model, "Test", null);
1659+
1660+
CompareModel("Entity.cs", expected, result);
1661+
}
1662+
16351663
[Fact]
16361664
public void Generates_Doc_Comments_For_Method()
16371665
{

Octokit.GraphQL.Core.Generation/DocCommentGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public static void GenerateSummary(string summary, int indentation, StringBuilde
2020

2121
private static void GenerateCommentBlock(string text, string indent, StringBuilder builder)
2222
{
23+
text = text.Replace("<", "&lt;").Replace(">", "&gt;");
24+
2325
foreach (var line in text.Split('\r', '\n'))
2426
{
2527
if (!string.IsNullOrWhiteSpace(line))

0 commit comments

Comments
 (0)