Skip to content

Commit 9a9ef63

Browse files
committed
Merge pull request #1593 from sharwell/fix-1590
Fix escaped quotes in XML attributes
2 parents ac76ee5 + 1096591 commit 9a9ef63

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/HelperTests/XmlSyntaxFactoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void TestPlainTextAttribute()
1717
Assert.Equal(" name=\"value\"", XmlSyntaxFactory.TextAttribute("name", "value").ToFullString());
1818
}
1919

20-
[Fact(Skip = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1590")]
20+
[Fact]
2121
public void TestEscapedTextAttribute()
2222
{
2323
Assert.Equal(" name=\""value"\"", XmlSyntaxFactory.TextAttribute("name", "\"value\"").ToFullString());

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/XmlSyntaxFactory.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static XmlTextSyntax Text(params SyntaxToken[] textTokens)
6666

6767
public static XmlTextAttributeSyntax TextAttribute(string name, string value)
6868
{
69-
return TextAttribute(name, TextLiteral(value));
69+
return TextAttribute(name, TextLiteral(value, true));
7070
}
7171

7272
public static XmlTextAttributeSyntax TextAttribute(string name, params SyntaxToken[] textTokens)
@@ -142,8 +142,18 @@ public static SyntaxToken TextNewLine(string text, bool continueComment)
142142
}
143143

144144
public static SyntaxToken TextLiteral(string value)
145+
{
146+
return TextLiteral(value, false);
147+
}
148+
149+
public static SyntaxToken TextLiteral(string value, bool escapeQuotes)
145150
{
146151
string encoded = new XText(value).ToString();
152+
if (escapeQuotes)
153+
{
154+
encoded = encoded.Replace("\"", """);
155+
}
156+
147157
return SyntaxFactory.XmlTextLiteral(
148158
SyntaxFactory.TriviaList(),
149159
encoded,

0 commit comments

Comments
 (0)