Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If [link=] contains whitespace, error parsing as style is thrown #1658

Open
kzu opened this issue Oct 4, 2024 · 0 comments
Open

If [link=] contains whitespace, error parsing as style is thrown #1658

kzu opened this issue Oct 4, 2024 · 0 comments

Comments

@kzu
Copy link
Contributor

kzu commented Oct 4, 2024

Repro:

#r "nuget: Spectre.Console, 0.49.1"
using Spectre.Console;

var file = @"C:\Foo Bar\Baz.mp4";
var title = string.Join(Path.DirectorySeparatorChar, file.Split(Path.DirectorySeparatorChar)[^2..]);

AnsiConsole.MarkupInterpolated($"[link={file}]{title}[/]");

Removing the space (or replacing it with a dot, say), fixes it:

Exception:

   at Spectre.Console.StyleParser.Parse(String text) in /_/src/Spectre.Console/StyleParser.cs:line 10
   at Spectre.Console.MarkupParser.Parse(String text, Style style) in /_/src/Spectre.Console/Internal/Text/Markup/MarkupParser.cs:line 29
   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:\Users\dev\AppData\Local\Temp\roslynpad\build\ad7038b6246d417a81e61589c1da40cf\Program.cs:line 7

I think it would be safe to detect the [link= prefix and effective do a replace of common invalid URL chars such as spaces > %20 and perhaps a few others.

Not sure if this can be considered a bug or a feature request :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant