From c1cb72dd31c97e17483f73bf2cc67ee399bdcf22 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Mon, 8 Apr 2024 15:26:52 +1000 Subject: [PATCH] fix: correctly encode strings (#1203) Fixes #1199 --- go-runtime/encoding/encoding.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/go-runtime/encoding/encoding.go b/go-runtime/encoding/encoding.go index f7e3c6eb4f..819a68c212 100644 --- a/go-runtime/encoding/encoding.go +++ b/go-runtime/encoding/encoding.go @@ -141,10 +141,8 @@ func encodeStruct(v reflect.Value, w *bytes.Buffer) error { } func encodeBytes(v reflect.Value, w *bytes.Buffer) error { - w.WriteRune('"') data := base64.StdEncoding.EncodeToString(v.Bytes()) - w.WriteString(data) - w.WriteRune('"') + fmt.Fprintf(w, "%q", data) return nil } @@ -199,9 +197,7 @@ func encodeFloat(v reflect.Value, w *bytes.Buffer) error { } func encodeString(v reflect.Value, w *bytes.Buffer) error { - w.WriteRune('"') - fmt.Fprintf(w, "%s", v.String()) - w.WriteRune('"') + fmt.Fprintf(w, "%q", v.String()) return nil }