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

Commit a2ed012

Browse files
committed
Fix StackOverflow in NonAsciiRewriter
It is incorrect for the visitor to call the base visit method one a literal node we don't rewrite. Doing so causes stack overflow due to infinite recursion.
1 parent 03b1c05 commit a2ed012

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ class Test
4848
Verify(text, expected);
4949
}
5050

51+
[Fact]
52+
public void NonAsciiRewriterHandlesNonStringLiterals()
53+
{
54+
var text = @"
55+
using System;
56+
57+
class Test
58+
{
59+
public const int OkayInt = 12345;
60+
}
61+
";
62+
63+
Verify(text, text);
64+
}
65+
5166
internal override IFormattingRule GetFormattingRule()
5267
{
5368
return new Rules.NonAsciiChractersAreEscapedInLiterals();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
5050
return RewriteCharacterLiteralExpression(node);
5151
}
5252

53-
return base.Visit(node);
53+
return node;
5454
}
5555

5656
private static SyntaxNode RewriteStringLiteralExpression(LiteralExpressionSyntax node)

0 commit comments

Comments
 (0)