-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obsolete Encoding.UTF7 property and UTF7Encoding ctors #37535
Obsolete Encoding.UTF7 property and UTF7Encoding ctors #37535
Conversation
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs
Show resolved
Hide resolved
@@ -111,7 +111,9 @@ public void Encoding_ISCIIAssemese() | |||
public void Encoding_UTF7() | |||
{ | |||
Debug.WriteLine("Verifying UTF7Encoding Encoding"); | |||
#pragma warning disable BCL0001 // Encoding.UTF7 property is obsolete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do obsoletion IDs need to be numerical? If not, have we considered using more descriptive names that would avoid the need for a comment? May not be a great idea to break from convention even if it's possible.
src/libraries/System.IO.Ports/tests/SerialPort/Read_char_int_int.cs
Outdated
Show resolved
Hide resolved
case CodePageUTF7: // 65000 | ||
{ | ||
// Support for UTF-7 is disabled by default. It can be re-enabled by registering a custom | ||
// provider (which early-exits this method before the 'switch' statement) or by using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What custom provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call Encoding.RegisterProvider
, you can override the return value of Encoding.GetEncoding("utf-7")
, Encoding.GetEncoding("utf-8")
, and any other encoding instance. If you register a custom provider for UTF-7, we never query the AppContext
switch because this switch statement never get hit.
Registering a custom provider doesn't change the return value of the built-in accelerators (like Encoding.UTF7
or Encoding.UTF8
) since they're hardcoded to always use the built-in implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. It's the "re-enabled" lingo that confuses me. There's no way for someone to get at our built-in Encoding to "re-enable" it via Encoding.RegisterProvider, is there? They've have to implement one from scratch, no?
src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Ports/tests/SerialPort/Read_char_int_int.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http.Json/tests/UnitTests/TranscodingReadStreamTests.cs
Show resolved
Hide resolved
@eerhardt Anything we want to adjust here to make it easy for the linker to strip the UTF7Encoding? |
src/libraries/System.Private.CoreLib/src/System/LocalAppContextSwitches.cs
Outdated
Show resolved
Hide resolved
Yes, as it exists today the linker won't be able to strip UTF7Encoding since it is being rooted by To enable stripping, we can make the new switch a full blown feature switch. You can see an example of this in #38129. Basically the thing we will want to add is an entry into this file runtime/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml Lines 2 to 6 in 38aa0b7
that tells the linker when Something like: <type fullname="System.LocalAppContextSwitches">
<method signature="System.Boolean get_EnableUnsafeUTF7Encoding()" body="stub" value="false" feature="Switch.System.Text.Encoding.EnableUnsafeUTF7Encoding" featurevalue="false" />
</type> |
Thanks @eerhardt for the tip! I'll plumb it through in the next iteration. |
Drop switch prefix Disallow Encoding.GetEncoding from seeing an EncodingProvider-returned UTF-7 encoding
@@ -3,5 +3,8 @@ | |||
<type fullname="System.Globalization.GlobalizationMode"> | |||
<method signature="System.Boolean get_Invariant()" body="stub" value="true" feature="System.Globalization.Invariant" featurevalue="true" /> | |||
</type> | |||
<type fullname="System.LocalAppContextSwitches"> | |||
<method signature="System.Boolean get_EnableUnsafeUTF7Encoding()" body="stub" value="true" feature="System.Text.Encoding.EnableUnsafeUTF7Encoding" featurevalue="true" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reversed to me. I believe that this would allow UTF7Encoding to be unconditionally enabled; but not trimmed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. Even though the default value is false, we still want trimming to take place if somebody has set false.
@jkotas any idea why the wasm tests might be failing? [23:20:06] dbug: test[0]
[FAIL] System.Text.Encodings.Tests.EncodingMiscTests.NormalizationTest(codepage: 65000, normalized: False, normalizedC: False, normalizedD: False, normalizedKC: False, normalizedKD: False)
[23:20:06] dbug: test[0]
System.NotSupportedException : Support for UTF-7 is disabled. See https://aka.ms/dotnet-warnings/MSLIB0001 for more information. There is a runtimeconfig.template.json file present in that test directory which re-enables the UTF-7 code paths, so the test project succeeds on all other platforms. See https://github.com/dotnet/runtime/blob/9d6811c5753d0d627d608a4d5d932aee014f43e5/src/libraries/System.Text.Encoding/tests/runtimeconfig.template.json. |
Awesome - thanks both for the pointer! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @GrabYourPitchforks. LGTM.
@GrabYourPitchforks just checking, did you log and fill a breaking change template for this one? sorry if I missed it. |
@tarekgh Not yet, thanks for the reminder. :) |
Breaking change notification: dotnet/docs#19274 |
Resolves #32284.
Breaking changes
Encoding.UTF7
is now obsolete as warning (diagnostic id BCL0001).UTF7Encoding
constructors are now obsolete as warning (diagnostic id BCL0001). The type itself is not obsolete in order to allow code likeif (x is UTF7Encoding)
to continue to work without warning.Encoding.GetEncoding(65000 /* UTF-7 code page */)
andEncoding.GetEncoding("utf-7")
will now throw an "unknown code page" exception.AppContext
can be used to re-enableEncoding.GetEncoding
recognizing the string "utf-7" or the code page 65000.This resulted in some changes to unit tests. /cc @carlossanlop @jozkee @dotnet/ncl to review their areas of ownership and to make sure I didn't torpedo the tests. For the System.Net.Http.Json UTF-7 tests, I removed the test body entirely rather than suppressing, as the point of this change was to disallow
HttpClient
and friends from honoringContent-Type: ...; charset=utf-7
without explicit opt-in by the app developer./cc @terrajobst as well since this our first usage of the "better obsoletion" APIs that were added, so we should settle on URL and diagnostic id prefix.