diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs index 32e26bf78aabb06f7b21cc3575975edbc04219f1..9c4aa552e5dd3c23f07deb5db7789b6fe05609c6 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs @@ -133,7 +133,7 @@ internal static string FormatLiteral(bool value) return value ? "true" : "false"; } - private static void FormatChar( + private static void FormatStringChar( ref PooledStringBuilder pooledBuilder, string str, int index, @@ -273,7 +273,7 @@ public static string FormatLiteral(string value, ObjectDisplayOptions options) } for (int i = 0; i < value.Length; i++) { - FormatChar(ref pooledBuilder, value, i, value[i], quote, useLanguageSpecificEscapes: true, useUnicodeEscapes: true); + FormatStringChar(ref pooledBuilder, value, i, value[i], quote, useLanguageSpecificEscapes: true, useUnicodeEscapes: true); } if (quote != 0) { @@ -295,7 +295,7 @@ internal static string FormatString(string str, bool useQuotes) builder.Append(quote); for (int i = 0; i < str.Length; i++) { - FormatChar(ref pooledBuilder, str, i, str[i], quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: false); + FormatStringChar(ref pooledBuilder, str, i, str[i], quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: false); } builder.Append(quote); return pooledBuilder.ToStringAndFree(); @@ -320,13 +320,13 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options) builder.Append(options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers) ? "0x" + ((int)c).ToString("x4") : ((int)c).ToString()); builder.Append(" "); } - if (quote != 0) + if (useQuotes) { builder.Append(quote); } var escapeNonPrintable = !includeCodePoints; - FormatChar(ref pooledBuilder, null, 0, c, quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: !includeCodePoints); - if (quote != 0) + FormatStringChar(ref pooledBuilder, null, 0, c, quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: !includeCodePoints); + if (useQuotes) { builder.Append(quote); } diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs index c6eb3f7030c6b4290f10ae03e79b7c1b66fb2e90..53c4f9357ad221d02c27ce2cc7ebd9a8a6282e5f 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs @@ -155,6 +155,7 @@ public void Strings() } var s = sb.ToString(); + // Formatting with quotes should escape specific control characters. var expected = "\"\\0\u0001\u0002\u0003\u0004\u0005\u0006\\a\\b\\t\\n\\v\\f\\r\u000e\u000f\u0010" + "\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d" + @@ -168,6 +169,7 @@ public void Strings() expected, ObjectDisplay.FormatString(s, useQuotes: true)); + // Formatting without quotes should not escape any characters. expected = "\0\u0001\u0002\u0003\u0004\u0005\u0006\a\u0008\u0009\u000a\u000b\f\u000d\u000e\u000f\u0010" + "\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d" + diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 898ea42e15674b55917d7ac741d82bcffbdc500b..68a29dea0fd811b7af203a55daf8b903f787c2e1 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -228,15 +228,16 @@ public void TestLiteralDefaultStringValues() CheckLiteralToString("A", @"""A"""); CheckLiteralToString("\r", @"""\r"""); CheckLiteralToString("\u0007", @"""\a"""); + CheckLiteralToString("\u000c", @"""\f"""); CheckLiteralToString("\u001f", @"""\u001f"""); // char CheckLiteralToString('A', @"'A'"); CheckLiteralToString('\r', @"'\r'"); + CheckLiteralToString('\u0007', @"'\a'"); CheckLiteralToString('\u000c', @"'\f'"); CheckLiteralToString('\u001f', @"'\u001f'"); - // byte CheckLiteralToString(byte.MinValue, @"0"); CheckLiteralToString(byte.MaxValue, @"255"); diff --git a/src/ExpressionEvaluator/VisualBasic/Test/ResultProvider/BasicResultProviderTest.vbproj b/src/ExpressionEvaluator/VisualBasic/Test/ResultProvider/BasicResultProviderTest.vbproj index ef62e1cec259bc1c7a96129586dbd215bbc24b1e..531b87fc3575424b32d61ebb61c930abb1d35513 100644 --- a/src/ExpressionEvaluator/VisualBasic/Test/ResultProvider/BasicResultProviderTest.vbproj +++ b/src/ExpressionEvaluator/VisualBasic/Test/ResultProvider/BasicResultProviderTest.vbproj @@ -107,9 +107,6 @@ - - -