Skip to content

Commit

Permalink
address pr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed Jan 22, 2024
1 parent 9fede70 commit 9d64e0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pkg/httpserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"os"
"strings"
"text/template"

ucfg "github.com/elastic/go-ucfg"
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/httpserver/httpserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestHTTPServer(t *testing.T) {
{{ minify_json ` + "`" + `
{
"key1": "value1",
"key2": "value2"
"key2": "<value2>"
}
` + "`" + `}}
`
Expand Down Expand Up @@ -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":"<value2>"}`, string(body))
})
}

Expand Down

0 comments on commit 9d64e0a

Please sign in to comment.