File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
System.Private.CoreLib/src/System/Text
System.Runtime/tests/System/Text Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ internal static void AddProvider(EncodingProvider provider)
7171
7272 var newProviders = new EncodingProvider [ providers . Length + 1 ] ;
7373 Array . Copy ( providers , newProviders , providers . Length ) ;
74- providers [ ^ 1 ] = provider ;
74+ newProviders [ ^ 1 ] = provider ;
7575
7676 if ( Interlocked . CompareExchange ( ref s_providers , newProviders , providers ) == providers )
7777 {
Original file line number Diff line number Diff line change 33
44using System . Collections . Generic ;
55using System . Linq ;
6+ using Microsoft . DotNet . RemoteExecutor ;
67using Moq ;
78using Xunit ;
89
@@ -106,6 +107,25 @@ public void GetEncodings_FromProvider_DoesNotContainDisallowedEncodings(string e
106107 } ) ;
107108 }
108109
110+ [ ConditionalFact ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
111+ public void RegisterProvider_EncodingsAreUsable ( )
112+ {
113+ RemoteExecutor . Invoke ( ( ) =>
114+ {
115+ for ( int i = 0 ; i < 10 ; i ++ )
116+ {
117+ Encoding . RegisterProvider ( new NullEncodingProvider ( ) ) ;
118+ Assert . Same ( Encoding . UTF8 , Encoding . GetEncoding ( 65001 ) ) ;
119+ }
120+ } ) . Dispose ( ) ;
121+ }
122+
123+ private sealed class NullEncodingProvider : EncodingProvider
124+ {
125+ public override Encoding GetEncoding ( int codepage ) => null ;
126+ public override Encoding GetEncoding ( string name ) => null ;
127+ }
128+
109129 private sealed class ThreadStaticEncodingProvider : EncodingProvider
110130 {
111131 private static readonly object _globalRegistrationLockObj = new object ( ) ;
You can’t perform that action at this time.
0 commit comments