@@ -519,6 +519,7 @@ public static void TestDefaultEncodings()
519
519
Assert . Contains ( mappedEncoding , CrossplatformDefaultEncodings ( ) . Union ( CodePageInfo ( ) . Select ( i => Map ( ( int ) i [ 0 ] , ( string ) i [ 1 ] ) ) ) ) ;
520
520
521
521
TestRegister1252 ( ) ;
522
+ TestMultiBytesEncodingsSupportSurrogate ( ) ;
522
523
}
523
524
524
525
private static void ValidateDefaultEncodings ( )
@@ -639,6 +640,23 @@ public static void TestEncodingDisplayNames(int codePage, string webName, string
639
640
Assert . All ( name , c => Assert . True ( c >= ' ' && c < '~' + 1 , "Name: " + name + " contains character: " + c ) ) ;
640
641
}
641
642
643
+ private static void TestMultiBytesEncodingsSupportSurrogate ( )
644
+ {
645
+ Encoding . RegisterProvider ( CodePagesEncodingProvider . Instance ) ;
646
+
647
+ Encoding encoding = Encoding . GetEncoding ( "GB18030" ) ;
648
+ Assert . NotNull ( encoding ) ;
649
+
650
+ string surrogatePair = "\uD840 \uDE13 " ; // Surrogate Pair codepoint '𠈓' \U00020213
651
+ byte [ ] expectedBytes = new byte [ ] { 0x95 , 0x32 , 0xB7 , 0x37 } ;
652
+
653
+ Assert . Equal ( expectedBytes , encoding . GetBytes ( surrogatePair ) ) ;
654
+ Assert . Equal ( expectedBytes . Length , encoding . GetByteCount ( surrogatePair ) ) ;
655
+
656
+ Assert . Equal ( surrogatePair , encoding . GetString ( expectedBytes ) ) ;
657
+ Assert . Equal ( surrogatePair . Length , encoding . GetCharCount ( expectedBytes ) ) ;
658
+ }
659
+
642
660
// This test is run as part of the default mappings test, since it modifies global state which that test
643
661
// depends on.
644
662
private static void TestRegister1252 ( )
0 commit comments