maui
maui copied to clipboard
Label control TextType=Html causes unhandled exception.
Description
This appears to be broken again.
If I do a simple test with a full http link I get an Unhandled Exception: '=' is an unexpected token.
The ampersand also appears to cause an issue.
Steps to Reproduce
- Create new MAUI app.
- Add
Label
control to content page. - Set label's
TextType
toHtml
- In the code behind pass an http link such as:
<a class='more' href='https://www.motorsport.com/f1/news/vettel-on-hamilton-blocking-in-dutch-gp-i-cant-disappear/10364466/?utm_source=RSS&utm_medium=referral&utm_campaign=RSS-F1&utm_term=News&utm_content=www'>Keep reading</a>
- Project output type is
Windows
Link to public reproduction project repository
https://github.com/dotnet/maui/pull/976
Version with bug
6.0.424
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 10.0.19041.0
Did you find any workaround?
No, because for some reason in VS2022 when debugging MAUI, the StackTrace is always "null" and the CallStack just reads "External Code".
Relevant log output
No response
@GuildOfCalamity Try converting all of the "&" in your HTML to "&" - I'm betting the parser is confused because "&" usually indicates that you're escaping characters in HTML.
Unfortunately, I'm not sure that's going to help you much, because I don't think Windows supports anchor tags ("") as part of HTML Label text. You'd need to use a HyperLink
control on Windows, and I don't believe MAUI has a virtual control that maps to HyperLink
. So you may have to create a custom type and handler if you want to display links.
@hartez The ampersand conversion was my first thought as well, so I did try that but it kind of defeats the purpose of having the control offer the formatting. I can keep the control from crashing by doing the ampersand conversion "&
" but it will only show the link text and not the actual http route. I can't use the hyperlink control because this is the text body of a paragraph from the web site (which may or may not contain hyperlinks)
Just to be clear: At a minimum this control should not crash the application, and at a maximum it should be able to handle anchor tags (like the iOS version does). In it's current state I don't think anyone would ever use this feature for fear of it crashing their application.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I got rather excited when I discovered this feature. My excitement was quickly sent to the grave when my app started crashing immediately :(
Similar issue tested on latest MAUI workloads (maui-windows, 7.0.86/7.0.100, VS 17.6.33801.468
). All three of these crash my MAUI win app immediately (no exceptions or errors in debug output):
<Label Text="Just an ampersand: &" TextType="Html" />
<Label Text="Hello &nbsp; World" TextType="Html" />
<!-- <a href='https://www.google.com/search?q=abc&oq=abc'>Link</a> -->
<Label Text="<a href='https://www.google.com/search?q=abc&oq=abc'>Link</a>" TextType="Html" />
Note that this one doesn't crash, although the link doesn't work:
<!-- <a href='https://www.google.com/search?q=abc'>Link</a> -->
<Label Text="<a href='https://www.google.com/search?q=abc'>Link</a>" TextType="Html" />
So it would appear that this is more of an issue of when the html text output decodes to an ampersand value. No form of encoding has worked for me so far. Only solution has been to remove any ampersand escaping sequences altogether, but that doesn't really work well for URL links.
Verified this issue with Visual Studio Enterprise 17.9.0 Preview 1.0. Can repro on windows platform.