Skip to content

problem with markdown component when input is null or string.emptyΒ #976

@andreaspipp

Description

@andreaspipp

Describe the bug
If you use the markdown component and give as input a null value or an empty string the whole component won't work anymore because it throws an ArgumentOutOfException exception.

To Reproduce

  1. Go to the demo website of this component https://demos.blazorbootstrap.com/markdown#live-preview
  2. clear the complete text from the markdown textarea
  3. the preview won't render anymore if you type valid markdown in the textarea

OR
<Markdown style="max-height: 437px;overflow-y:auto;"> @string.Empty </Markdown>

Expected behavior
display an empty string if the input is null or an empty string

Screenshots
When debugging in VS 2022 the problem lies in the GetLines() function in Markdown.cs when list.Count = 0 and the function tries ao access an item at position -1.
image

Versions (please complete the following information):

  • .NET Version: .NET 9
  • BlazorBootstrap: 3.2.0
  • Blazor WebAssembly / Server: Blazor Server
  • Blazor Interactive Render Mode: Server

Sample code
Sample code to reproduce the issue.

GitHub repo
GitHub repo with minimal code to reproduce the issue.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 131

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions