System.InvalidOperationException may be thrown when using AnsiConsole.MarkupLineInterpolated to output a FormattableString with an object interpolated which overloads .ToString() method. What's worse, it may bring some unexpected strings without being escaped into the output.
To Reproduce
using Spectre.Console;
AnsiConsole.MarkupInterpolated($"{new Example()}");
class Example
{
public override string ToString()
{
return "[123]";
}
}
here is the output
PS C:\GitHub\********\test> dotnet run
Unhandled exception. System.InvalidOperationException: Encountered malformed markup tag at position 5.
at Spectre.Console.MarkupTokenizer.ReadMarkup() in /_/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs:line 192
at Spectre.Console.MarkupTokenizer.MoveNext() in /_/src/Spectre.Console/Internal/Text/Markup/MarkupTokenizer.cs:line 27
at Spectre.Console.MarkupParser.Parse(String text, Style style) in /_/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs:line 17
at Spectre.Console.AnsiConsoleExtensions.Markup(IAnsiConsole console, String value) in /_/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs:line 77
at Spectre.Console.AnsiConsoleExtensions.MarkupInterpolated(IAnsiConsole console, IFormatProvider provider, FormattableString value) in /_/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs:line 67
at Spectre.Console.AnsiConsoleExtensions.MarkupInterpolated(IAnsiConsole console, FormattableString value) in /_/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs:line 35
at Spectre.Console.AnsiConsole.MarkupInterpolated(FormattableString value) in /_/src/Spectre.Console/AnsiConsole.Markup.cs:line 42
at Program.<Main>$(String[] args) in C:\GitHub\********\test\Program.cs:line 3
Expected behavior
just output lines normally
[123] // without any styles
Screenshots
none
Additional context
none
Please upvote :+1: this issue if you are interested in it.
Information
Describe the bug
System.InvalidOperationException
may be thrown when usingAnsiConsole.MarkupLineInterpolated
to output aFormattableString
with an object interpolated which overloads.ToString()
method. What's worse, it may bring some unexpected strings without being escaped into the output.To Reproduce
here is the output
Expected behavior
just output lines normally
Screenshots
none
Additional context
none
Please upvote :+1: this issue if you are interested in it.