Stop HTML-escaping string values in JSON output - #557
Conversation
|
Thanks for the PR. This is actually a duplicate of #556 but it isn't merged yet as I was waiting for a writer option to be able to turn this back on if needed |
|
Ah, I missed #556 when I checked for open PRs, apologies for the duplicate. Happy to close this in favour of it. On the writer option you are waiting for: the escapeHTML := w.options.Ext["json-escape-html"] == "true"with Want me to push that onto #556, or open it as a follow-up so you can merge #556 first? Either is fine, and if you would rather do it yourself, no problem at all. |
|
Closing this in favour of #556. If it helps, the flag you asked for there looks like a small addition on top: Happy to push that onto #556 or send it as a follow-up once that merges, whichever suits you. No need if you would rather keep it in-house. |
Fixes #552.
What's broken
JSON output escapes
<,>and&as\uXXXX, so ordinary strings come back unreadable.Repro
The fix
goccy/go-jsonHTML-escapes by default, same asencoding/json. The writer now passesjson.DisableHTMLEscape(). dasel transforms data rather than emitting HTML, so there is no injection context the escaping was protecting, and this matches whatjqand similar tools output.Blast radius is scalar values only. Object keys never reach this encoder,
writeMapwrites them withfmt.Fprintf.After:
Verification
Added a round-trip test in
parsing/json/json_test.goover a string holding>,<and&. It fails against the old writer withsetuptools>=77.0.3 & <100.0and passes with the fix.go test ./...is green. Also checked non-ASCII is unaffected:café → ok ✓round-trips literally.