maui icon indicating copy to clipboard operation
maui copied to clipboard

Label control TextType=Html causes unhandled exception.

Open GuildOfCalamity opened this issue 2 years ago • 4 comments

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

  1. Create new MAUI app.
  2. Add Label control to content page.
  3. Set label's TextType to Html
  4. 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>
  5. 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 avatar Sep 20 '22 15:09 GuildOfCalamity

@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 avatar Sep 20 '22 17:09 hartez

@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 "&#38;" 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)

GuildOfCalamity avatar Sep 20 '22 17:09 GuildOfCalamity

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.

GuildOfCalamity avatar Sep 21 '22 12:09 GuildOfCalamity

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.

ghost avatar Sep 21 '22 18:09 ghost

I got rather excited when I discovered this feature. My excitement was quickly sent to the grave when my app started crashing immediately :(

dotMorten avatar May 22 '23 19:05 dotMorten

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: &amp;" TextType="Html" />
<Label Text="Hello &amp;nbsp; World" TextType="Html" />
<!-- <a href='https://www.google.com/search?q=abc&oq=abc'>Link</a> -->
<Label Text="&lt;a href=&#39;https://www.google.com/search?q=abc&amp;oq=abc&#39;&gt;Link&lt;/a&gt;" 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="&lt;a href=&#39;https://www.google.com/search?q=abc&#39;&gt;Link&lt;/a&gt;" 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.

gerneio avatar Jun 20 '23 16:06 gerneio

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 1.0. Can repro on windows platform.

Zhanglirong-Winnie avatar Nov 29 '23 09:11 Zhanglirong-Winnie