Skip to content

htmlEscape property in ToJson using Newtonsoft release 4.5.4 #680

@cmberge

Description

@cmberge

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions