spectre.console
spectre.console copied to clipboard
MarkupLine does not escape given parameters.
Information
- OS: Windows (but probably everywhere)
- Version: 0.41.0
- Terminal: Windows Terminal (but probably everywhere)
Describe the bug
I encountared this in a situation like this:
var list = new List<int>() { 1337, 42 };
_ansiConsole.MarkupLine("[gray]Log[/]: {0}", list);
which threw this exception: System.InvalidOperationException: Could not find color or style 'System.Int32'.
The problem seems to be that the parameters are applied before parsing the format. How to format the string should be defined in the format string and not applied to the parameters.
_ansiConsole.MarkupLine("[gray]Log[/]: {0}", "[not a style]");
@FreeApophis Thanks for reporting this, but this is by design. The Markup API expects all format arguments that are strings to be properly escaped.
It would break too many consumers if we would change this behavior now. We're, however, considering adding new functionality in a later release that takes care of this problem.
Hello, I run into the same issue today. What about a simply static method, which escapes all relevant sequences from a string (and a method to reverse the escaping). Then it is easy to embedded strings into MarkupLine and escape it when necessary?
There is one: EscapeMarkup
Wow, I did not notice this. In this case, everything is in place I would say. Thanks 👍