Pārlūkot izejas kodu

Fixes #2655. Should be avoid cast to char on a Rune ctor which always fallback for a UTF16 char. (#2656)

BDisp 2 gadi atpakaļ
vecāks
revīzija
59a7ff95b3
2 mainītis faili ar 11 papildinājumiem un 2 dzēšanām
  1. 2 2
      UICatalog/Scenarios/CharacterMap.cs
  2. 9 0
      UnitTests/Text/RuneTests.cs

+ 2 - 2
UICatalog/Scenarios/CharacterMap.cs

@@ -332,7 +332,7 @@ class CharMap : ScrollView {
 	}
 	}
 
 
 	private void CopyCodePoint () => Clipboard.Contents = $"U+{SelectedCodePoint:x5}";
 	private void CopyCodePoint () => Clipboard.Contents = $"U+{SelectedCodePoint:x5}";
-	private void CopyGlyph () => Clipboard.Contents = $"{new Rune ((char)SelectedCodePoint)}";
+	private void CopyGlyph () => Clipboard.Contents = $"{new Rune (SelectedCodePoint)}";
 
 
 	public override void OnDrawContent (Rect contentArea)
 	public override void OnDrawContent (Rect contentArea)
 	{
 	{
@@ -553,7 +553,7 @@ class CharMap : ScrollView {
 				//}
 				//}
 			}
 			}
 
 
-			var title = $"{ToCamelCase (name)} - {new Rune ((char)SelectedCodePoint)} U+{SelectedCodePoint:x4}";
+			var title = $"{ToCamelCase (name)} - {new Rune (SelectedCodePoint)} U+{SelectedCodePoint:x4}";
 			switch (MessageBox.Query (title, decResponse, "Copy _Glyph", "Copy Code _Point", "Cancel")) {
 			switch (MessageBox.Query (title, decResponse, "Copy _Glyph", "Copy Code _Point", "Cancel")) {
 			case 0:
 			case 0:
 				CopyGlyph ();
 				CopyGlyph ();

+ 9 - 0
UnitTests/Text/RuneTests.cs

@@ -711,4 +711,13 @@ public class RuneTests {
 		Assert.Equal (utf16Length, r.Utf16SequenceLength);
 		Assert.Equal (utf16Length, r.Utf16SequenceLength);
 		Assert.Equal (utf8Length, r.Utf8SequenceLength);
 		Assert.Equal (utf8Length, r.Utf8SequenceLength);
 	}
 	}
+
+	[Fact]
+	public void Cast_To_Char_Durrogate_Pair_Return_UTF16 ()
+	{
+		Assert.NotEqual ("𝔹", $"{new Rune (unchecked((char)0x1d539))}");
+		Assert.Equal ("픹", $"{new Rune (unchecked((char)0x1d539))}");
+		Assert.Equal ("픹", $"{new Rune (0xd539)}");
+		Assert.Equal ("𝔹", $"{new Rune (0x1d539)}");
+	}
 }
 }