diff --git a/src/Controls/src/Core/Label/Label.iOS.cs b/src/Controls/src/Core/Label/Label.iOS.cs index b57efccbd65f..acecf544543f 100644 --- a/src/Controls/src/Core/Label/Label.iOS.cs +++ b/src/Controls/src/Core/Label/Label.iOS.cs @@ -42,7 +42,7 @@ internal static void MapFormatting(ILabelHandler handler, Label label) { LabelHandler.MapFormatting(handler, label); } - else + else if (!label.HasFormattedTextSpans && label.TextType == TextType.Html) // we need to re-apply color and font for HTML labels { handler.UpdateValue(nameof(ILabel.TextColor)); handler.UpdateValue(nameof(ILabel.Font)); diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29851.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29851.cs new file mode 100644 index 000000000000..a42e383e8e84 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29851.cs @@ -0,0 +1,23 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 29851, "[iOS] FormattedText with text color causes stack overflow", PlatformAffected.All)] +public class Issue29851 : TestContentPage +{ + protected override void Init() + { + Content = new Label + { + AutomationId = "label", + TextColor = Colors.Green, + FormattedText = new FormattedString + { + Spans = + { + new Span { Text = "Hello, World!" }, + new Span { Text = "*", TextColor = Colors.Red } + } + } + }; + ; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29851.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29851.cs new file mode 100644 index 000000000000..34689e7cab06 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29851.cs @@ -0,0 +1,20 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue29851 : _IssuesUITest +{ + + public Issue29851(TestDevice testDevice) : base(testDevice) { } + + public override string Issue => "[iOS] FormattedText with text color causes stack overflow"; + + [Test] + [Category(UITestCategories.Label)] + public void FormattedTextWithTextColorDoesNotCrash() + { + App.WaitForElement("label"); + } +} \ No newline at end of file