diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs index c8e223ab7955b..b3fc802b3b84a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs @@ -18,8 +18,7 @@ internal static class HttpRuleParser internal const int MaxInt64Digits = 19; internal const int MaxInt32Digits = 10; - // iso-8859-1, Western European (ISO) - internal static readonly Encoding DefaultHttpEncoding = Encoding.GetEncoding(28591); + internal static Encoding DefaultHttpEncoding => Encoding.Latin1; private static bool[] CreateTokenChars() { diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs index 3f0d0350610ba..18d25839a3b66 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs @@ -491,11 +491,8 @@ public bool IsReadOnly public static Encoding ASCII => ASCIIEncoding.s_default; - // Returns an encoding for the Latin1 character set. The returned encoding - // will be an instance of the Latin1Encoding class. - // - // This is for our optimizations - private static Encoding Latin1 => Latin1Encoding.s_default; + /// Gets an encoding for the Latin1 character set (ISO-8859-1). + public static Encoding Latin1 => Latin1Encoding.s_default; // Returns the number of bytes required to encode the given character // array. diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 3354c138715fa..f5430eb69355a 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -10201,6 +10201,7 @@ protected Encoding(int codePage, System.Text.EncoderFallback? encoderFallback, S public virtual bool IsMailNewsSave { get { throw null; } } public bool IsReadOnly { get { throw null; } } public virtual bool IsSingleByte { get { throw null; } } + public static System.Text.Encoding Latin1 { get { throw null; } } public virtual System.ReadOnlySpan Preamble { get { throw null; } } public static System.Text.Encoding Unicode { get { throw null; } } public static System.Text.Encoding UTF32 { get { throw null; } } diff --git a/src/libraries/System.Text.Encoding/tests/Latin1Encoding/Latin1EncodingTests.cs b/src/libraries/System.Text.Encoding/tests/Latin1Encoding/Latin1EncodingTests.cs index 5d80c31619063..2054bef9d2735 100644 --- a/src/libraries/System.Text.Encoding/tests/Latin1Encoding/Latin1EncodingTests.cs +++ b/src/libraries/System.Text.Encoding/tests/Latin1Encoding/Latin1EncodingTests.cs @@ -9,6 +9,14 @@ namespace System.Text.Tests { public class Latin1EncodingTests { + [Fact] + public void Encoding_Latin1_ExpectedObject() + { + Assert.NotNull(Encoding.Latin1); + Assert.Same(Encoding.Latin1, Encoding.Latin1); + Assert.Same(Encoding.GetEncoding("iso-8859-1"), Encoding.Latin1); + } + [Fact] public void Ctor() { @@ -21,6 +29,7 @@ public void Ctor() public static IEnumerable Encodings_TestData() { + yield return new object[] { Encoding.Latin1 }; yield return new object[] { Encoding.GetEncoding("latin1") }; yield return new object[] { Encoding.GetEncoding("iso-8859-1") }; } @@ -64,6 +73,7 @@ public void Clone(Encoding encoding) public static IEnumerable Equals_TestData() { + yield return new object[] { Encoding.GetEncoding("latin1"), Encoding.Latin1, true }; yield return new object[] { Encoding.GetEncoding("latin1"), Encoding.GetEncoding("latin1"), true }; yield return new object[] { Encoding.GetEncoding("latin1"), Encoding.GetEncoding("iso-8859-1"), true };