Open martin-honnen opened 1 year ago
The relevant code seems to be in https://github.com/dotnet/maui/blob/17790124c566d73001761ea93a447876e4ed0b90/src/Controls/src/Core/Platform/Windows/Extensions/TextBlockExtensions.cs#L59 where
switch (label.TextType)
{
case TextType.Html:
platformControl.UpdateTextHtml(label);
break;
calls platformControl.UpdateTextHtml(label)
doing (in https://github.com/dotnet/maui/blob/17790124c566d73001761ea93a447876e4ed0b90/src/Compatibility/Core/src/Windows/LabelRenderer.cs#L365)
void UpdateTextHtml(TextBlock textBlock)
{
var text = Element.Text ?? String.Empty;
// Just in case we are not given text with elements.
var modifiedText = string.Format("<div>{0}</div>", text);
modifiedText = Regex.Replace(modifiedText, "<br>", "<br></br>", RegexOptions.IgnoreCase);
// reset the text because we will add to it.
Control.Inlines.Clear();
try
{
var element = XElement.Parse(modifiedText);
LabelHtmlHelper.ParseText(element, Control.Inlines, Element);
}
catch (Exception)
{
// if anything goes wrong just show the html
textBlock.Text = global::Windows.Data.Html.HtmlUtilities.ConvertToText(Element.Text);
}
}
For the used HTML markup sample that crashes, I would think that XElement.Parse(modifiedText)
gives an exception so that textBlock.Text = global::Windows.Data.Html.HtmlUtilities.ConvertToText(Element.Text);
should kick in as a fallback but somehow the global::Windows.Data.Html.HtmlUtilities.ConvertToText(Element.Text)
seems to make app crash.
Does anyone know where/how this is implemented? I only find such a class/method if the UWP documentation.
I have set up an NUnit test project targeting <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
and simple tests like
using Windows.Data.Html;
namespace WinUITest1;
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test1()
{
Assert.DoesNotThrow(() =>
{
var result = HtmlUtilities.ConvertToText("<p>This is a test.</p>");
Assert.AreEqual("This is a test.", result);
});
}
[Test]
public void Test2()
{
Assert.DoesNotThrow(() =>
{
var result = HtmlUtilities.ConvertToText("<p>This is paragraph 1.<p>This is paragraph 2.");
Assert.AreEqual("This is paragraph 1.\nThis is paragraph 2.", result);
});
}
}
run through without any crashes/exceptions/problems.
So why could global::Windows.Data.Html.HtmlUtilities.ConvertToText(Element.Text)
in MAUI cause problems?
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.
Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Windows 11 with provided Project: MauiLabelTextTypeHtmlTests.zip
We are having similar issues with rendering some types of html in the label control. Windows freezes and iOS throws null-ref.
Description
I am trying to use the
Label
control withTextType
set toHtml
and found that on Windows that might make my app crash once I do that with certain samples of HTML markup assigned asText
, or, for this sample test case with a static Label and the TextType set as Html with some certain, seemingly harmless HTML markup like<Label TextType="Html"><![CDATA[<p>This is paragraph 1.<p>This is paragraph 2.]]></Label>
, the app window doesn't come up at all.Steps to Reproduce
Link to public reproduction project repository
https://github.com/martin-honnen/MauiLabelTextTypeHtmlTests/tree/ParagraphsCrash
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows 11, maui-windows 7.0.49/7.0.100
Did you find any workaround?
No, it seems certain, seemingly harmless/simple HTML fragments set as
Text
of aLabel
withTextType="Html"
make the app not show up at all when set statically (or make the app window crash/disappear when assigned dynamically after the app start).Relevant log output