You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When calling MarkupLineInterpolated on an interpolated string, where one of the interpolation holes is an object who's string representation contains square brackets, AnsiConsole throws an unhandled exception:
System.InvalidOperationException: 'Could not find color or style 'contains,'.'
To Reproduce
usingSpectre.Console;string_string="string";int_int=123;CoolThing_other_cool_thing=new();Console.WriteLine($"I have a {_string} and an {_int} and a {_other_cool_thing}");// worksAnsiConsole.MarkupLineInterpolated($"I have a {_string} and an {_int} and a {_other_cool_thing}");// crashesAnsiConsole.MarkupLineInterpolated($"I have a {_string} and an {_int} and a {_other_cool_thing.ToString()}");// works, triggers IDE0071classCoolThing{publicoverridestringToString()=>"This[contains, braces].";}
Expected behavior
All three Console/AnsiConsole lines print the same text to the console and none of them crash.
Additional context
The third print statement triggers the IDE0071 code analysis rule because calling ToString() on the value inside an interpolated string is supposed to be entirely redundant.
It seems that Markup.EscapeInterpolated only escapes strings and does not consider any other values could require escaping. Thus, pre-converting the object to a string avoids the error, but then the IDE goes "why did you do that, that's not necessary" and suggests code to the user which will then crash.
I would expect that if an object is intending to supply markup it is tagged somehow to do so, and all other objects would implicitly have their output escaped. (Doing so may require a custom interpolated string handler, rather than just hooking into FormattableString.)
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered:
Information
Describe the bug
When calling
MarkupLineInterpolated
on an interpolated string, where one of the interpolation holes is an object who's string representation contains square brackets,AnsiConsole
throws an unhandled exception:To Reproduce
Expected behavior
All three
Console
/AnsiConsole
lines print the same text to the console and none of them crash.Additional context
The third print statement triggers the IDE0071 code analysis rule because calling ToString() on the value inside an interpolated string is supposed to be entirely redundant.
It seems that
Markup.EscapeInterpolated
only escapes strings and does not consider any other values could require escaping. Thus, pre-converting the object to a string avoids the error, but then the IDE goes "why did you do that, that's not necessary" and suggests code to the user which will then crash.I would expect that if an object is intending to supply markup it is tagged somehow to do so, and all other objects would implicitly have their output escaped. (Doing so may require a custom interpolated string handler, rather than just hooking into
FormattableString
.)Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: