From 81ad695ef72fa3c95313e2689454e6b761d74f30 Mon Sep 17 00:00:00 2001 From: Thomas Nind <31306100+tznind@users.noreply.github.com> Date: Sun, 12 Jan 2025 17:05:52 +0000 Subject: [PATCH] Fix foreach runes bug with unicode surrogate pairs (#3894) --- Terminal.Gui/Text/TextFormatter.cs | 2 +- UnitTests/Views/LabelTests.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index a4a8b7060..f426d7659 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -2124,7 +2124,7 @@ public class TextFormatter var start = string.Empty; var i = 0; - foreach (Rune c in text) + foreach (Rune c in text.EnumerateRunes ()) { if (c == hotKeySpecifier && i == hotPos) { diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index c58be7974..b798fbe80 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -1460,4 +1460,16 @@ e Application.Top.Dispose (); Application.ResetState (); } + + // https://github.com/gui-cs/Terminal.Gui/issues/3893 + [Fact] + [SetupFakeDriver] + public void TestLabelUnderscoreMinus () + { + var lbl = new Label () + { + Text = "TextView with some more test_- text. Unicode shouldn't 𝔹Aℝ𝔽!" + }; + lbl.Draw (); + } }