Explorar o código

Fix HTML escape encoding

Signed-off-by: Ulysses Souza <[email protected]>
Ulysses Souza %!s(int64=5) %!d(string=hai) anos
pai
achega
74e86ab06a
Modificáronse 3 ficheiros con 13 adicións e 15 borrados
  1. 1 1
      cli/cmd/inspect.go
  2. 2 2
      formatter/formatter.go
  3. 10 12
      formatter/json.go

+ 1 - 1
cli/cmd/inspect.go

@@ -56,7 +56,7 @@ func runInspect(ctx context.Context, id string) error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	fmt.Println(j)
+	fmt.Print(j)
 
 
 	return nil
 	return nil
 }
 }

+ 2 - 2
formatter/formatter.go

@@ -38,11 +38,11 @@ func Print(toJSON interface{}, format string, outWriter io.Writer, writerFn func
 			s := reflect.ValueOf(toJSON)
 			s := reflect.ValueOf(toJSON)
 			for i := 0; i < s.Len(); i++ {
 			for i := 0; i < s.Len(); i++ {
 				obj := s.Index(i).Interface()
 				obj := s.Index(i).Interface()
-				jsonLine, err := ToCompressedJSON(obj)
+				jsonLine, err := ToJSON(obj, "", "")
 				if err != nil {
 				if err != nil {
 					return err
 					return err
 				}
 				}
-				_, _ = fmt.Fprintln(outWriter, jsonLine)
+				_, _ = fmt.Fprint(outWriter, jsonLine)
 			}
 			}
 		default:
 		default:
 			outJSON, err := ToStandardJSON(toJSON)
 			outJSON, err := ToStandardJSON(toJSON)

+ 10 - 12
formatter/json.go

@@ -17,6 +17,7 @@
 package formatter
 package formatter
 
 
 import (
 import (
+	"bytes"
 	"encoding/json"
 	"encoding/json"
 )
 )
 
 
@@ -24,18 +25,15 @@ const standardIndentation = "    "
 
 
 // ToStandardJSON return a string with the JSON representation of the interface{}
 // ToStandardJSON return a string with the JSON representation of the interface{}
 func ToStandardJSON(i interface{}) (string, error) {
 func ToStandardJSON(i interface{}) (string, error) {
-	b, err := json.MarshalIndent(i, "", standardIndentation)
-	if err != nil {
-		return "", err
-	}
-	return string(b), nil
+	return ToJSON(i, "", standardIndentation)
 }
 }
 
 
-// ToCompressedJSON return a string with the JSON representation of the interface{}
-func ToCompressedJSON(i interface{}) (string, error) {
-	b, err := json.Marshal(i)
-	if err != nil {
-		return "", err
-	}
-	return string(b), nil
+// ToJSON return a string with the JSON representation of the interface{}
+func ToJSON(i interface{}, prefix string, indentation string) (string, error) {
+	buffer := &bytes.Buffer{}
+	encoder := json.NewEncoder(buffer)
+	encoder.SetEscapeHTML(false)
+	encoder.SetIndent(prefix, indentation)
+	err := encoder.Encode(i)
+	return buffer.String(), err
 }
 }