Skip to content

Don't escape '<>&' symbols in JSON

Adam Cohen requested to merge set-escape-html-false-when-encoding-json into main

What does this MR do?

This MR replaces json.Marshal with json.NewEncoder in order to set SetEscapeHTML(false). This is necessary because using json.Marshal causes <>& characters to be escaped, which means if we want to use the > character, as in this example:

{ "value": "coveralls:3.0.0 > log-driver:1.2.6 > codecov.io:0.0.1 > request:2.42.0 > hawk:1.1.1" }

this will instead be escaped and show up in the JSON report as:

{ "value": "coveralls:3.0.0 \u003e log-driver:1.2.6 \u003e codecov.io:0.0.1 \u003e request:2.42.0 \u003e hawk:1.1.1" }

As of go 1.18, it's still not possible to override the escapeHTML option, since it's hardcoded to true, so that's why we need to use json.NewEncoder instead of json.Marshal.

What are the relevant issue numbers?

Show one `shortest path` on the finding details... (gitlab-org/gitlab#348532 - closed)

Does this MR meet the acceptance criteria?

Merge request reports