Skip to content

Commit

Permalink
fix: correctly encode strings (#1203)
Browse files Browse the repository at this point in the history
Fixes #1199
  • Loading branch information
alecthomas authored Apr 8, 2024
1 parent 9946716 commit c1cb72d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions go-runtime/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c1cb72d

Please sign in to comment.