From 168f35202d3050c17770e0606bc736e2e88b59c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Fri, 26 Nov 2021 10:23:20 +0100 Subject: [PATCH] Fix exception formatting for generic methods (#639) The generic parameters were double escaped and would display as `[[T0,T1,TRet]]` instead of `[T0,T1,TRet]`. This is because the `builder.AppendWithStyle` method already escapes its value so the caller must not escape the passed value. --- src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs | 4 ++-- .../Expectations/Exception/CallSite.Output.verified.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs index 0d5a87ac0..e3778659a 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs @@ -149,12 +149,12 @@ private static string Emphasize(string input, char[] separators, Style color, bo { builder.AppendWithStyle( settings.Style.NonEmphasized, - type.Substring(0, index + 1).EscapeMarkup()); + type.Substring(0, index + 1)); } builder.AppendWithStyle( color, - type.Substring(index + 1, type.Length - index - 1).EscapeMarkup()); + type.Substring(index + 1, type.Length - index - 1)); } else { diff --git a/test/Spectre.Console.Tests/Expectations/Exception/CallSite.Output.verified.txt b/test/Spectre.Console.Tests/Expectations/Exception/CallSite.Output.verified.txt index 8a394f620..f2001d97a 100644 --- a/test/Spectre.Console.Tests/Expectations/Exception/CallSite.Output.verified.txt +++ b/test/Spectre.Console.Tests/Expectations/Exception/CallSite.Output.verified.txt @@ -1,6 +1,6 @@ System.InvalidOperationException: Something threw! System.InvalidOperationException: Throwing! - at Spectre.Console.Tests.Data.TestExceptions.GenericMethodThatThrows[[T0,T1,TRet]](Nullable`1 number) in /xyz/Exceptions.cs:nn + at Spectre.Console.Tests.Data.TestExceptions.GenericMethodThatThrows[T0,T1,TRet](Nullable`1 number) in /xyz/Exceptions.cs:nn at Spectre.Console.Tests.Data.TestExceptions.ThrowWithGenericInnerException() in /xyz/Exceptions.cs:nn at Spectre.Console.Tests.Data.TestExceptions.ThrowWithGenericInnerException() in /xyz/Exceptions.cs:nn at Spectre.Console.Tests.Unit.ExceptionTests.<>c.b__4_0() in /xyz/ExceptionTests.cs:nn