Skip to content
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

Refactor UTF-7 encoding detection #18384

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract to WarnIfObsolete
  • Loading branch information
xtqqczze committed Oct 25, 2022
commit f3b2fd4d506e750e0b1f7d372b2acb31841b501c
Original file line number Diff line number Diff line change
Expand Up @@ -7656,15 +7656,22 @@ public Encoding Encoding

set
{
// Check for UTF-7 by checking for code page 65000
// See: https://docs.microsoft.com/dotnet/core/compatibility/core-libraries/5.0/utf-7-code-paths-obsolete
if (value != null && value.CodePage == 65000)
{
_provider.WriteWarning(PathUtilsStrings.Utf7EncodingObsolete);
}
WarnIfObsolete(value);
xtqqczze marked this conversation as resolved.
Show resolved Hide resolved
_encoding = value;
// If an encoding was explicitly set, be sure to capture that.
WasStreamTypeSpecified = true;

void WarnIfObsolete(Encoding value)
{
const int CodePageUtf7 = 65000;

// Compare against the the well-known UTF-7 code page, see:
// https://docs.microsoft.com/dotnet/core/compatibility/core-libraries/5.0/utf-7-code-paths-obsolete
if (value is { CodePage: CodePageUtf7 })
{
_provider.WriteWarning(PathUtilsStrings.Utf7EncodingObsolete);
}
}
}
}

Expand Down