rc protocol: Encode strings values in an escape code safe way

Go emits UTF-8 encoded JSON not ascii encoded JSON. Still need to fix
lists and dicts of strings
This commit is contained in:
Kovid Goyal
2022-12-12 18:48:54 +05:30
parent 95e05ce9ec
commit aac57550c9
4 changed files with 78 additions and 8 deletions

View File

@@ -10,6 +10,25 @@ import (
"testing"
)
func TestEncodeJSON(t *testing.T) {
tests := map[string]string{
"a b\nc\td\a": `a b\nc\td\u0007`,
"•": `\u2022`,
"\U0001f123": `\ud83c\udd23`,
}
var s escaped_string
for x, expected := range tests {
s = escaped_string(x)
expected = `"` + expected + `"`
actualb, _ := s.MarshalJSON()
actual := string(actualb)
if expected != actual {
t.Fatalf("Failed for %#v\n%#v != %#v", x, expected, actual)
}
}
}
func TestCommandToJSON(t *testing.T) {
pv := fmt.Sprint(ProtocolVersion[0], ",", ProtocolVersion[1], ",", ProtocolVersion[2])
rc, err := create_rc_ls([]string{})