CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.86k stars 1.37k forks source link

ArgumentOutOfRangeException in the markdown parser with "r/Steam: www." #2926

Open Sergio0694 opened 5 years ago

Sergio0694 commented 5 years ago

I'm submitting a...

Current behavior

The MarkdownTextBlock throws an ArgumentOutOfRange exception when entering this string:

r/Steam: www.

NOTE: the issue is present even if the address is just "ww.", or with full URLs. Eg. "www.google.com" crashes as well, if the string starts with that "r/Steam: " prefix.

The crash happens exactly here: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/3b5a1f480d65c649a1732a8b8a11866ed3c08836/Microsoft.Toolkit.Parsers/Markdown/Inlines/TextRunInline.cs#L384

In particular, with the string mentioned in the title, it happens because the end parameter is 7, while the start parameter is 2, so the resulting length is negative.

Expected behavior

The markdown should be parsed correctly as usual.

Minimal reproduction of the problem with instructions

Environment

Nuget Package(s): `[...].Uwp.UI.Controls`

Package Version(s): `5.1.1`

Windows 10 Build Number:
- [] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [X] October 2018 Update (17763)
- [X] Insider Build (build number: 18362.x)

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [X] October 2018 Update (17763)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [X] 2019 Community
michael-hawker commented 5 years ago

@WilliamABradley have time to take a look?