Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 9ed44d4

Browse files
committed
Disable NonAsciiCharacter Rule on verbatim strings
The rewriting logic we have for verbatim strings is incorrect, since you can not use Unicode excape sequences inside them. Issue 39 tracks the correct fix, but for now, we'll just disable the rule on these sorts of strings.
1 parent d24b9ee commit 9ed44d4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/NonAsciiCharactersAreEscapedInLiteralsRuleTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,22 @@ public void DoNotAllowUnicodeInLiterals()
3636
class Test
3737
{{
3838
public static readonly string BadString = ""This has {0} and {1}, which are both bad."";
39-
public static readonly string AnotherBadString = @""This has {0} and {1}, which are both bad."";
39+
public static readonly string AnotherBadString = @""This has {0} and {1}, which are both bad, but we don't rewrite yet."";
4040
public const char BadChar = '{0}';
4141
}}
4242
", '\u2713', "\U0001F308");
4343

44-
var expected = @"
44+
var expected = string.Format(@"
4545
using System;
4646
4747
class Test
48-
{
48+
{{
4949
public static readonly string BadString = ""This has \u2713 and \U0001F308, which are both bad."";
50-
public static readonly string AnotherBadString = @""This has \u2713 and \U0001F308, which are both bad."";
50+
public static readonly string AnotherBadString = @""This has {0} and {1}, which are both bad, but we don't rewrite yet."";
5151
public const char BadChar = '\u2713';
52-
}
53-
";
52+
}}
53+
", '\u2713', "\U0001F308");
54+
5455
Verify(text, expected);
5556
}
5657

src/Microsoft.DotNet.CodeFormatting/Rules/NonAsciiCharactersAreEscapedInLiteralsRule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ private static SyntaxNode RewriteStringLiteralExpression(LiteralExpressionSyntax
5151
{
5252
Debug.Assert(node.CSharpKind() == SyntaxKind.StringLiteralExpression);
5353

54+
if (node.Token.IsVerbatimStringLiteral())
55+
{
56+
// We do not correctly rewrite verbatim string literals yet. Once Issue 39 is
57+
// fixed we can remove this early out.
58+
return node;
59+
}
60+
5461
if (HasNonAsciiCharacters(node.Token.Text))
5562
{
5663
string convertedText = EscapeNonAsciiCharacters(node.Token.Text);

0 commit comments

Comments
 (0)