Browse Source

Fix foreach runes bug with unicode surrogate pairs (#3894)

Thomas Nind 6 months ago
parent
commit
81ad695ef7
2 changed files with 13 additions and 1 deletions
  1. 1 1
      Terminal.Gui/Text/TextFormatter.cs
  2. 12 0
      UnitTests/Views/LabelTests.cs

+ 1 - 1
Terminal.Gui/Text/TextFormatter.cs

@@ -2124,7 +2124,7 @@ public class TextFormatter
         var start = string.Empty;
         var start = string.Empty;
         var i = 0;
         var i = 0;
 
 
-        foreach (Rune c in text)
+        foreach (Rune c in text.EnumerateRunes ())
         {
         {
             if (c == hotKeySpecifier && i == hotPos)
             if (c == hotKeySpecifier && i == hotPos)
             {
             {

+ 12 - 0
UnitTests/Views/LabelTests.cs

@@ -1460,4 +1460,16 @@ e
         Application.Top.Dispose ();
         Application.Top.Dispose ();
         Application.ResetState ();
         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 ();
+    }
 }
 }