From d9d3a9a869fe0190d97a9ae87f4e930e6d4179ec Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Fri, 17 Jan 2020 19:16:20 +1100 Subject: [PATCH 1/4] Fix for issue #1740 U+0085 not recognised as a newline character in CSharpCodeGenerator.cs Fix $1740 --- .../src/Microsoft/CSharp/CSharpCodeGenerator.cs | 1 + .../Compiler/CSharpCodeGenerationTests.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs b/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs index 8643d1a86cc7f..76806e79d1279 100644 --- a/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs +++ b/src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs @@ -125,6 +125,7 @@ private string QuoteSnippetStringCStyle(string value) break; case '\u2028': case '\u2029': + case '\u0085': AppendEscapedChar(b, value[i]); break; diff --git a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs index 5aec14aa1f956..0e5d46836a608 100644 --- a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs +++ b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs @@ -3449,5 +3449,21 @@ public static void Main() } }"); } + + [Fact] + public void SpecialNewLineCharactersInStringsDoneCorrectly() + { + var cd = new CodeTypeDeclaration("ClassWithStringFields") { IsClass = true }; + + var field = new CodeMemberField("System.String", "StringWithSpecialNewLines"); + field.Attributes = MemberAttributes.Public | MemberAttributes.Static; + field.InitExpression = new CodePrimitiveExpression("\u0085\u2028\u2029"); + cd.Members.Add(field); + + AssertEqual(cd, + @"public class ClassWithStringFields { + public static string StringWithNewLines = ""\u0085\u2028\u2029""; + }"); + } } } From 9553d254fb5128d6375d42a51f39af65460ac3ea Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Fri, 17 Jan 2020 20:07:45 +1100 Subject: [PATCH 2/4] Fix for issue #1740 U+0085 not recognised as a newline character in CSharpCodeGenerator.cs --- .../tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs index 0e5d46836a608..46d3f500a23c7 100644 --- a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs +++ b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs @@ -3462,7 +3462,7 @@ public void SpecialNewLineCharactersInStringsDoneCorrectly() AssertEqual(cd, @"public class ClassWithStringFields { - public static string StringWithNewLines = ""\u0085\u2028\u2029""; + public static string StringWithSpecialNewLines = ""\u0085\u2028\u2029""; }"); } } From 997cb316ac23ae35b9a1bcd64f230ac8a268b99f Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Fri, 17 Jan 2020 21:49:15 +1100 Subject: [PATCH 3/4] Fix for issue #1740 U+0085 not recognised as a newline character in CSharpCodeGenerator.cs This change fixes a previous test that incorrectly causes the character to be forced out of being in unicode format. --- .../tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs index 46d3f500a23c7..f152a53f46cd5 100644 --- a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs +++ b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs @@ -1066,7 +1066,7 @@ public void CharEncoding() AssertEqual(main, "public static void Main() { " + - " System.Console.WriteLine(\"\u1234 \u4567 \uABCD \\r \\n \\t \\\\ \\\" \\' \\0 \\u2028 \\u2029 \u0084 \u0085 \U00010F00\"); " + + " System.Console.WriteLine(\"\u1234 \u4567 \uABCD \\r \\n \\t \\\\ \\\" \\' \\0 \\u2028 \\u2029 \u0084 \\u0085 \U00010F00\"); " + "}"); } From 198d5f99b43b1d2a628af13ac4a60f1bb9e07918 Mon Sep 17 00:00:00 2001 From: Hamish Arblaster Date: Wed, 22 Jan 2020 14:23:47 +1100 Subject: [PATCH 4/4] Stop the changes from #1740 on the .Net Framework as per #1913 Read #1913 for why, view PR #1853 and #1740 also. --- .../Compiler/CSharpCodeGenerationTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs index f152a53f46cd5..8af54e4e6cfc5 100644 --- a/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs +++ b/src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs @@ -1054,6 +1054,25 @@ public int SecondReturnMethod(int intInput) { } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/1913", ~TargetFrameworkMonikers.NetFramework)] + public void CharEncodingNetFx() + { + string chars = "\u1234 \u4567 \uABCD \r \n \t \\ \" \' \0 \u2028 \u2029 \u0084 \u0085 \U00010F00"; + + var main = new CodeEntryPointMethod(); + main.Statements.Add( + new CodeMethodInvokeExpression( + new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(Console)), "WriteLine"), + new CodeExpression[] { new CodePrimitiveExpression(chars) })); + + AssertEqual(main, + "public static void Main() { " + + " System.Console.WriteLine(\"\u1234 \u4567 \uABCD \\r \\n \\t \\\\ \\\" \\' \\0 \\u2028 \\u2029 \u0084 \u0085 \U00010F00\"); " + + "}"); + } + + [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/1913", TargetFrameworkMonikers.NetFramework)] public void CharEncoding() { string chars = "\u1234 \u4567 \uABCD \r \n \t \\ \" \' \0 \u2028 \u2029 \u0084 \u0085 \U00010F00"; @@ -3451,6 +3470,7 @@ public static void Main() } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/1913", TargetFrameworkMonikers.NetFramework)] public void SpecialNewLineCharactersInStringsDoneCorrectly() { var cd = new CodeTypeDeclaration("ClassWithStringFields") { IsClass = true };