Ensure backslashes are always escaped

This commit is contained in:
Joshua Welsh 2018-11-07 10:46:21 +00:00
parent dc363de894
commit 82a6448692
No known key found for this signature in database
GPG Key ID: 40E3F42A5EB576FE
2 changed files with 2 additions and 2 deletions

View File

@ -108,7 +108,7 @@ func parsePath(path string) (pathResult, error) {
func mustMarshalString(s string) bool { func mustMarshalString(s string) bool {
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
if s[i] < ' ' || s[i] > 0x7f || s[i] == '"' || (s[i] == '\\' && i == len(s)-1) { if s[i] < ' ' || s[i] > 0x7f || s[i] == '"' || s[i] == '\\' {
return true return true
} }
} }

View File

@ -118,7 +118,7 @@ func TestBasic(t *testing.T) {
``, ``,
"\\:1.this.4", `4`) "\\:1.this.4", `4`)
testRaw(t, setRaw, testRaw(t, setRaw,
`{":\1":{"this":[null,null,null,null,{".HI":4}]}}`, `{":\\1":{"this":[null,null,null,null,{".HI":4}]}}`,
``, ``,
"\\:\\\\1.this.4.\\.HI", `4`) "\\:\\\\1.this.4.\\.HI", `4`)
testRaw(t, setRaw, testRaw(t, setRaw,