Skip to content

htmlEscape property in ToJson using Newtonsoft release 4.5.4 #680

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

Open
cmberge opened this issue Dec 3, 2024 · 0 comments
Open

htmlEscape property in ToJson using Newtonsoft release 4.5.4 #680

cmberge opened this issue Dec 3, 2024 · 0 comments

Comments

@cmberge
Copy link

cmberge commented Dec 3, 2024

In the file ExtensionMethods.cs there are two different implementations of ToJson. We are currently using the Newtonsoft version, for which we can optionally use htmlEscape. However, in MiniProfiler release 4.5.4, the STJSON version is used, in which the htmlEscape parameter is not used.

Was it intentional not to use the htmlEscape option in STJSON?
And is it possible to create a version in which newtonsoft/htmlEscape can be used?

Newtonsoft:

/// <summary>
/// Renders the parameter <see cref="MiniProfiler"/> to JSON.
/// </summary>
/// <param name="profiler">The <see cref="MiniProfiler"/> to serialize.</param>
/// <param name="htmlEscape">Whether to HTML escape the output.</param>
[return: NotNullIfNotNull(nameof(profiler))]
public static string? ToJson(this MiniProfiler? profiler, bool htmlEscape = false) =>
    profiler != default
    ? (htmlEscape ? JsonConvert.SerializeObject(profiler, htmlEscapeSettings) : JsonConvert.SerializeObject(profiler, defaultSettings))
    : null;

STJSON:

/// <summary>
/// Renders the parameter <see cref="MiniProfiler"/> to JSON.
/// </summary>
/// <param name="profiler">The <see cref="MiniProfiler"/> to serialize.</param>
/// <param name="htmlEscape">Whether to HTML escape the output.</param>
[return: NotNullIfNotNull(nameof(profiler))]
[SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Compatibility across versions")]
public static string? ToJson(this MiniProfiler? profiler, bool htmlEscape = false) =>
    profiler != default
    ? JsonSerializer.Serialize(profiler, defaultSettings)
    : null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant