Skip to content

"Input string was not in a correct format" error with AnsiConsole.Write() #1495

@codeconscious

Description

@codeconscious

Information

  • OS: macOS Ventura (13.4.1)
  • Version: 0.46.0
  • Terminal: zsh

Describe the bug
A string containing the text {Pt.1} (TEST ~ 855D) causes AnsiConsole.Write() to throw the following exception:

System.FormatException: Input string was not in a correct format. Failure to parse near offset 1. Expected an ASCII digit.
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at Spectre.Console.AnsiConsole.Write(IFormatProvider provider, String format, Object[] args) in /_/src/Spectre.Console/AnsiConsole.Write.cs:line 247
   at Spectre.Console.AnsiConsole.Write(String format, Object[] args) in /_/src/Spectre.Console/AnsiConsole.Write.cs:line 235
   at Spectre.Console.AnsiConsole.Write(String value) in /_/src/Spectre.Console/AnsiConsole.Write.cs:line 14

Interestingly, this does not occur with AnsiConsole.WriteLine(). Also, using EscapeMarkup() on the string does not resolve the issue.

Similarly-formatted strings behave identically. I believe it's likely some of the text is unexpectedly being treated as markup.

I hope this is information is sufficient. Please let me know if you need anything more or if perhaps I'm overlooking anything (including a potential workaround). Thank you much.

To Reproduce

string text = @"{Pt.1} (TEST ~ 855D)";
AnsiConsole.WriteLine(text); // OK
AnsiConsole.WriteLine(text.EscapeMarkup()); // OK
AnsiConsole.Write(text); // Throws the error
AnsiConsole.Write(text.EscapeMarkup()); // Throws the error

Expected behavior
All lines written successfully to the terminal with markup-like text not treated as markup.

Screenshots
None.

Additional context
None.


Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo 🕑

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions