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

The App will crash when DescriptionAttribute contains middle bracket '[]' #1725

Open
riyueniao opened this issue Jan 7, 2025 · 1 comment

Comments

@riyueniao
Copy link

Describe the bug
When DescriptionAttribute contains a middle bracket, the app will crash with the following exception when printing the usage message.

Unhandled exception. System.InvalidOperationException: Encountered malformed markup tag at position 56.
   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 19
   at Spectre.Console.Markup..ctor(String text, Style style) in /_/src/Spectre.Console/Widgets/Markup.cs:line 42
   at Spectre.Console.Cli.Composer.Measure(RenderOptions options, Int32 maxWidth) in /_/src/Spectre.Console.Cli/Internal/Composer.cs:line 123
   at Spectre.Console.TableMeasurer.MeasureColumn(TableColumn column, Int32 maxWidth) in /_/src/Spectre.Console/Widgets/Table/TableMeasurer.cs:line 107
   at Spectre.Console.TableMeasurer.<>c__DisplayClass7_0.<CalculateColumnWidths>b__0(TableColumn column) in /_/src/Spectre.Console/Widgets/Table/TableMeasurer.cs:line 57
   at System.Linq.Enumerable.SelectListIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.SelectListIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Spectre.Console.TableMeasurer.CalculateColumnWidths(Int32 maxWidth) in /_/src/Spectre.Console/Widgets/Table/TableMeasurer.cs:line 57
   at Spectre.Console.Table.Render(RenderOptions options, Int32 maxWidth) in /_/src/Spectre.Console/Widgets/Table/Table.cs:line 140
   at Spectre.Console.Rendering.Renderable.Spectre.Console.Rendering.IRenderable.Render(RenderOptions options, Int32 maxWidth) in /_/src/Spectre.Console/Rendering/Renderable.cs:line 19
   at Spectre.Console.Rendering.JustInTimeRenderable.Render(RenderOptions context, Int32 width) in /_/src/Spectre.Console/Rendering/JustInTimeRenderable.cs:line 21
   at Spectre.Console.Rendering.Renderable.Spectre.Console.Rendering.IRenderable.Render(RenderOptions options, Int32 maxWidth) in /_/src/Spectre.Console/Rendering/Renderable.cs:line 19
   at Spectre.Console.RenderableExtensions.GetSegments(IAnsiConsole console, RenderOptions options, IEnumerable`1 renderables) in /_/src/Spectre.Console/Extensions/RenderableExtensions.cs:line 37
   at Spectre.Console.RenderableExtensions.GetSegments(IRenderable renderable, IAnsiConsole console) in /_/src/Spectre.Console/Extensions/RenderableExtensions.cs:line 29
   at Spectre.Console.AnsiBuilder.Build(IAnsiConsole console, IRenderable renderable) in /_/src/Spectre.Console/Internal/Backends/Ansi/AnsiBuilder.cs:line 17
   at Spectre.Console.AnsiConsoleBackend.Write(IRenderable renderable) in /_/src/Spectre.Console/Internal/Backends/Ansi/AnsiConsoleBackend.cs:line 30
   at Spectre.Console.AnsiConsoleFacade.Write(IRenderable renderable) in /_/src/Spectre.Console/Internal/Backends/AnsiConsoleFacade.cs:line 40
   at Spectre.Console.Cli.AnsiConsoleExtensions.SafeRender(IAnsiConsole console, IEnumerable`1 renderables) in /_/src/Spectre.Console.Cli/Internal/Extensions/AnsiConsoleExtensions.cs:line 33
   at Spectre.Console.Cli.CommandExecutor.Execute(IConfiguration configuration, IEnumerable`1 args) in /_/src/Spectre.Console.Cli/Internal/CommandExecutor.cs:line 80
   at Spectre.Console.Cli.CommandApp.RunAsync(IEnumerable`1 args) in /_/src/Spectre.Console.Cli/CommandApp.cs:line 84
   at Spectre.Console.Cli.CommandApp.Run(IEnumerable`1 args) in /_/src/Spectre.Console.Cli/CommandApp.cs:line 58

To Reproduce

[CommandOption("--some-nums <SomeNumbers>")]
[Description("The numbers to use. Default is [1,2,3,4].")]
public int[] SomeNumbers { get; set; } = [1,2,3,4];

Expected behavior
No crash happened after adding '[' in the description message.
Or error with a more user-friendly message.

@riyueniao riyueniao added bug Something isn't working needs triage labels Jan 7, 2025
@github-project-automation github-project-automation bot moved this to Todo 🕑 in Spectre Console Jan 7, 2025
@patriksvensson patriksvensson added feature and removed bug Something isn't working labels Jan 7, 2025
@patriksvensson
Copy link
Contributor

Not a bug since this is the expected behavior. Changed this to a feature request to provide a better error message.

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

No branches or pull requests

2 participants