From ab3e70ae9ff33bdf1fcfbd3dcb31129cc75672f3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 12 Jul 2019 20:37:34 -0700 Subject: [PATCH] Fix escape characters in trace command (#2822) --- cmd/admin-trace.go | 14 ++++++++++---- cmd/flags.go | 4 ---- cmd/main.go | 7 ++++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd/admin-trace.go b/cmd/admin-trace.go index e420325b..65c52403 100644 --- a/cmd/admin-trace.go +++ b/cmd/admin-trace.go @@ -181,9 +181,14 @@ func shortTrace(ti madmin.TraceInfo) shortTraceMsg { } func (s shortTraceMsg) JSON() string { - traceJSONBytes, e := json.MarshalIndent(s, "", " ") - fatalIf(probe.NewError(e), "Unable to marshal into JSON.") - return string(traceJSONBytes) + buf := &bytes.Buffer{} + enc := json.NewEncoder(buf) + enc.SetIndent("", " ") + // Disable escaping special chars to display XML tags correctly + enc.SetEscapeHTML(false) + + fatalIf(probe.NewError(enc.Encode(s)), "Unable to marshal into JSON.") + return buf.String() } func (s shortTraceMsg) String() string { @@ -247,7 +252,8 @@ func (t traceMessage) JSON() string { enc.SetIndent("", " ") // Disable escaping special chars to display XML tags correctly enc.SetEscapeHTML(false) - enc.Encode(trc) + fatalIf(probe.NewError(enc.Encode(trc)), "Unable to marshal into JSON.") + // strip off extra newline added by json encoder return strings.TrimSuffix(buf.String(), "\n") } diff --git a/cmd/flags.go b/cmd/flags.go index 70a75685..944ba8e5 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -29,10 +29,6 @@ var commandsTree = trie.NewTrie() // Collection of mc flags currently supported var globalFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "autocompletion", - Usage: "install auto-completion for your shell", - }, cli.StringFlag{ Name: "config-dir, C", Value: mustGetMcConfigDir(), diff --git a/cmd/main.go b/cmd/main.go index c6108537..705b6369 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -39,7 +39,12 @@ import ( var ( // global flags for mc. - mcFlags = []cli.Flag{} + mcFlags = []cli.Flag{ + cli.BoolFlag{ + Name: "autocompletion", + Usage: "install auto-completion for your shell", + }, + } ) // Help template for mc