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

Avoid modifying the JavaScriptEncoder on SystemTextJsonOutputFormatter #39778

Closed
wants to merge 1 commit into from

Conversation

pranavkm
Copy link
Contributor

By default, STJ encodes most non-ASCII characters which is different from Newtonsoft.Json's
defaults. When we first defaulted to STJ in 3.1, MVC attempted to minimize this difference by
using a more compatible (unsafe-relaxed) encoding scheme if a user hadn't explicitly configured one via
JsonOptions.

As noted in #38720, this causes issues if a
JsonSerializerContext is configured. This PR changes the output formatter to no longer
change the JavaScriptEncoder. Users can manually configure the unsafe-relaxed encoding
globally if they understand the consequences of doing so.

Contributes to #38720

{PR title}

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

{Detail}

Fixes #{bug number} (in this specific format)

By default, STJ encodes most non-ASCII characters which is different from Newtonsoft.Json's
defaults. When we first defaulted to STJ in 3.1, MVC attempted to minimize this difference by
using a more compatible (unsafe-relaxed) encoding scheme if a user hadn't explicitly configured one via
JsonOptions.

As noted in dotnet#38720, this causes issues if a
JsonSerializerContext is configured. This PR changes the output formatter to no longer
change the JavaScriptEncoder. Users can manually configure the unsafe-relaxed encoding
globally if they understand the consequences of doing so.

Contributes to dotnet#38720
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 26, 2022
@pranavkm pranavkm closed this Feb 4, 2022
@pranavkm pranavkm deleted the prkrishn/default-encoding branch February 4, 2022 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant