From 4db607839c034a67d599528b477843d3e9b50ae2 Mon Sep 17 00:00:00 2001 From: Neal Gafter Date: Sun, 6 Mar 2016 18:17:34 -0800 Subject: [PATCH] Work around CLR unicode bug with classification of U+2028 Fixes #9484 --- .../CSharp/Portable/SymbolDisplay/ObjectDisplay.cs | 9 +++++++-- .../CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs index a3f96cc628702..4729992f26c13 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs @@ -149,8 +149,7 @@ private static bool TryReplaceQuote(char c, char quote, out string replaceWith) /// /// Returns true if the character should be replaced and sets - /// to the replacement text if the - /// character is replaced with text other than the Unicode escape sequence. + /// to the replacement text. /// private static bool TryReplaceChar(char c, out string replaceWith) { @@ -184,6 +183,12 @@ private static bool TryReplaceChar(char c, out string replaceWith) case '\v': replaceWith = "\\v"; break; + case '\u2028': + // U+2028 "LINE SEPARATOR" should be classified by CharUnicodeInfo.GetUnicodeCategory as + // UnicodeCategory.LineSeparator but due to a bug is incorrectly categorized as + // UnicodeCategory.Format. See https://github.com/dotnet/coreclr/issues/3542 + replaceWith = "\\u2028"; + break; } if (replaceWith != null) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 2759630f374d4..a42a744ce41bc 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -352,6 +352,14 @@ public void TestLiteralToStringDifferentCulture() CultureInfo.CurrentCulture = culture; } + [WorkItem(9484, "https://github.com/dotnet/roslyn/issues/9484")] + [Fact] + public void TestEscapeLineSeparator() + { + var literal = SyntaxFactory.Literal("\u2028"); + Assert.Equal("\"\\u2028\"", literal.Text); + } + private static void CheckLiteralToString(dynamic value, string expected) { var literal = SyntaxFactory.Literal(value);