From 9d64e0addd37044b832a1f3fc4a5fba45b792947 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Tue, 23 Jan 2024 07:42:12 +1030 Subject: [PATCH] address pr comment --- pkg/httpserver/config.go | 8 ++++++-- pkg/httpserver/httpserver_test.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/httpserver/config.go b/pkg/httpserver/config.go index 61e76f6..12fd4d0 100644 --- a/pkg/httpserver/config.go +++ b/pkg/httpserver/config.go @@ -8,6 +8,7 @@ import ( "encoding/json" "errors" "os" + "strings" "text/template" ucfg "github.com/elastic/go-ucfg" @@ -102,6 +103,9 @@ func file(path string) (string, error) { } func minify(body string) (string, error) { - b, err := json.Marshal(json.RawMessage(body)) - return string(b), err + var buf strings.Builder + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + err := enc.Encode(json.RawMessage(body)) + return strings.TrimSpace(buf.String()), err } diff --git a/pkg/httpserver/httpserver_test.go b/pkg/httpserver/httpserver_test.go index 3b1d59b..3fa011f 100644 --- a/pkg/httpserver/httpserver_test.go +++ b/pkg/httpserver/httpserver_test.go @@ -63,7 +63,7 @@ func TestHTTPServer(t *testing.T) { {{ minify_json ` + "`" + ` { "key1": "value1", - "key2": "value2" + "key2": "" } ` + "`" + `}} ` @@ -162,7 +162,7 @@ func TestHTTPServer(t *testing.T) { require.NoError(t, err) resp.Body.Close() - assert.Equal(t, `{"key1":"value1","key2":"value2"}`, string(body)) + assert.Equal(t, `{"key1":"value1","key2":""}`, string(body)) }) }