summaryrefslogtreecommitdiff
path: root/cmd/podman/formats/formats.go
diff options
context:
space:
mode:
authorBoaz Shuster <ripcurld.github@gmail.com>2018-04-10 09:29:42 +0000
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-10 14:05:25 +0000
commit864b9c06c08b1c1649c5b845029404f7c275408d (patch)
treece0a4c2fa296dfd2787e12d6a7bbc5389d137e19 /cmd/podman/formats/formats.go
parent1700f2b2381d9665810ed4764d0fe357150c5978 (diff)
downloadpodman-864b9c06c08b1c1649c5b845029404f7c275408d.tar.gz
podman-864b9c06c08b1c1649c5b845029404f7c275408d.tar.bz2
podman-864b9c06c08b1c1649c5b845029404f7c275408d.zip
Unescape characters in inspect JSON format output
This patch changes the way the inspect command output is displayed on the screen when the format is set to JSON. Note: if the output is redirected to a file the output is *not* escaped. For example, before this commit if you run: $ sudo podman inspect --format "json" daveimg [ { ... "Author": "Dave \u003cdave@corp.io\u003e", } ... ] with this patch the output will be: [ { ... "Author": "Dave <dave@corp.io>", } ... ] Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com> Closes: #602 Approved by: mheon
Diffstat (limited to 'cmd/podman/formats/formats.go')
-rw-r--r--cmd/podman/formats/formats.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/cmd/podman/formats/formats.go b/cmd/podman/formats/formats.go
index bfd773c45..3da0ea385 100644
--- a/cmd/podman/formats/formats.go
+++ b/cmd/podman/formats/formats.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "io"
"os"
"strings"
"text/tabwriter"
@@ -55,12 +56,23 @@ type YAMLStruct struct {
Output interface{}
}
+func setJSONFormatEncoder(isTerminal bool, w io.Writer) *json.Encoder {
+ enc := json.NewEncoder(w)
+ enc.SetIndent("", " ")
+ if isTerminal {
+ enc.SetEscapeHTML(false)
+ }
+ return enc
+}
+
// Out method for JSON Arrays
func (j JSONStructArray) Out() error {
- data, err := json.MarshalIndent(j.Output, "", " ")
- if err != nil {
+ buf := bytes.NewBuffer(nil)
+ enc := setJSONFormatEncoder(terminal.IsTerminal(int(os.Stdout.Fd())), buf)
+ if err := enc.Encode(j.Output); err != nil {
return err
}
+ data := buf.Bytes()
// JSON returns a byte array with a literal null [110 117 108 108] in it
// if it is passed empty data. We used bytes.Compare to see if that is