From 2de406bb9e26df19a31b5f6111bb221b60964d48 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 20 Feb 2023 00:42:27 -0800 Subject: [PATCH] encoding/json: use append for HTMLEscape MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use append for HTMLEscape similar to Indent and Compact. Move it to indent.go alongside Compact, as it shares similar logic. In a future CL, we will modify appendCompact to be written in terms of appendHTMLEscape, but we need to first move the JSON decoder logic out of the main loop of appendCompact. Change-Id: I131c64cd53d5d2b4ca798b37349aeefe17b418c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/471198 TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Run-TryBot: Joseph Tsai Reviewed-by: Daniel Martí Reviewed-by: Than McIntosh Reviewed-by: Johan Brandhorst-Satzkorn Auto-Submit: Joseph Tsai --- src/encoding/json/encode.go | 46 ++++--------------------------------- src/encoding/json/indent.go | 30 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index ff0e40d532..de639aa008 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -183,41 +183,6 @@ func MarshalIndent(v any, prefix, indent string) ([]byte, error) { return b2, nil } -// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029 -// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029 -// so that the JSON will be safe to embed inside HTML