U+0085 not recognised as a newline character in CSharpCodeGenerator.cs (#1740) (...
authorHamish Arblaster <hamarb123@gmail.com>
Thu, 23 Jan 2020 17:48:36 +0000 (04:48 +1100)
committerStephen Toub <stoub@microsoft.com>
Thu, 23 Jan 2020 17:48:36 +0000 (12:48 -0500)
* Fix for issue #1740

U+0085 not recognised as a newline character in CSharpCodeGenerator.cs

Fix $1740

* Fix for issue #1740

U+0085 not recognised as a newline character in CSharpCodeGenerator.cs

* 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.

* Stop the changes from #1740 on the .Net Framework as per #1913

Read #1913 for why, view PR #1853 and #1740 also.

src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs
src/libraries/System.CodeDom/tests/System/CodeDom/Compiler/CSharpCodeGenerationTests.cs

index 8643d1a..76806e7 100644 (file)
@@ -125,6 +125,7 @@ namespace Microsoft.CSharp
                         break;
                     case '\u2028':
                     case '\u2029':
+                    case '\u0085':
                         AppendEscapedChar(b, value[i]);
                         break;
 
index 5aec14a..8af54e4 100644 (file)
@@ -1054,7 +1054,8 @@ namespace System.CodeDom.Compiler.Tests
         }
 
         [Fact]
-        public void CharEncoding()
+        [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";
 
@@ -1071,6 +1072,24 @@ namespace System.CodeDom.Compiler.Tests
         }
 
         [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";
+
+            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]
         public void DefaultValues()
         {
             var main = new CodeEntryPointMethod();
@@ -3449,5 +3468,22 @@ namespace System.CodeDom.Compiler.Tests
                       }
                   }");
         }
+
+        [Fact]
+        [ActiveIssue("https://github.com/dotnet/runtime/issues/1913", TargetFrameworkMonikers.NetFramework)]
+        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 StringWithSpecialNewLines = ""\u0085\u2028\u2029"";
+                  }");
+        }
     }
 }