Skip to content

Commit ae42d61

Browse files
committed
feat(cli.go): replace json.Marshal with custom jsonMarshal function to prevent HTML escaping and maintain consistent indentation
1 parent 482a21d commit ae42d61

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/cli/cli.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (app *App) Run() {
149149
app.kong.FatalIfErrorf(err, "failed to extract missing fields from source")
150150
}
151151

152-
if source, err = json.Marshal(sourceMap); err != nil {
152+
if source, err = jsonMarshal(sourceMap); err != nil {
153153
app.kong.FatalIfErrorf(err, "failed to marshal source map")
154154
}
155155
}
@@ -180,7 +180,7 @@ func (app *App) Run() {
180180
}
181181
dragoman.JSONMerge(originalOutMap, resultMap)
182182

183-
marshaled, err := json.MarshalIndent(originalOutMap, "", " ")
183+
marshaled, err := jsonMarshal(originalOutMap)
184184
if err != nil {
185185
app.kong.FatalIfErrorf(err, "failed to marshal result map")
186186
}
@@ -253,3 +253,12 @@ func readAll(r io.Reader) (out []byte, err error) {
253253
}
254254
}
255255
}
256+
257+
func jsonMarshal(v any) ([]byte, error) {
258+
var buf bytes.Buffer
259+
enc := json.NewEncoder(&buf)
260+
enc.SetEscapeHTML(false)
261+
enc.SetIndent("", " ")
262+
err := enc.Encode(v)
263+
return buf.Bytes(), err
264+
}

0 commit comments

Comments
 (0)