From 65f2c541668abba172de2a7f9f5999a5f41f6600 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 11 Nov 2021 16:42:51 +0100 Subject: [PATCH] Fix #2544: do not transform to interpolated string, if the format string is not syntactically correct. --- .../TestCases/Pretty/CS6_StringInterpolation.cs | 2 ++ ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS6_StringInterpolation.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS6_StringInterpolation.cs index 48d718479..049e5677e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS6_StringInterpolation.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS6_StringInterpolation.cs @@ -19,6 +19,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine($"\ta{args ?? args}"); Console.WriteLine($"\ta{args[0][0] == 'a'}"); Console.WriteLine($"\ta{$"a{args.Length}" == args[0]}"); + Console.WriteLine($"\ta{args.Length}}}"); } public static void ArrayExpansionSpecialCases(object[] args) @@ -54,6 +55,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine(string.Format("{0:}", args.Length)); Console.WriteLine(string.Format("{0{a}0}", args.Length)); Console.WriteLine(string.Format("test: {0}", string.Join(",", args))); + Console.WriteLine(string.Format("test: {0}}", args.Length)); #pragma warning restore } diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index e6e276a7a..cac87ab51 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -670,9 +670,14 @@ namespace ICSharpCode.Decompiler.CSharp sb.Clear(); kind = TokenKind.String; } + else if (Peek() == '}') + { + sb.Append("}}"); + Next(); + } else { - sb.Append((char)next); + yield return (TokenKind.Error, null); } break; case ':':