@@ -519,6 +519,7 @@ public static void TestDefaultEncodings()
519519 Assert . Contains ( mappedEncoding , CrossplatformDefaultEncodings ( ) . Union ( CodePageInfo ( ) . Select ( i => Map ( ( int ) i [ 0 ] , ( string ) i [ 1 ] ) ) ) ) ;
520520
521521 TestRegister1252 ( ) ;
522+ TestMultiBytesEncodingsSupportSurrogate ( ) ;
522523 }
523524
524525 private static void ValidateDefaultEncodings ( )
@@ -639,6 +640,23 @@ public static void TestEncodingDisplayNames(int codePage, string webName, string
639640 Assert . All ( name , c => Assert . True ( c >= ' ' && c < '~' + 1 , "Name: " + name + " contains character: " + c ) ) ;
640641 }
641642
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+
642660 // This test is run as part of the default mappings test, since it modifies global state which that test
643661 // depends on.
644662 private static void TestRegister1252 ( )
0 commit comments