Merge pull request #24 from Jawshua/string-escaping-failure

Fix backslashes not being escaped correctly
This commit is contained in:
Josh Baker 2018-11-15 03:30:24 -07:00 committed by GitHub
commit c943cc8c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 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,
@ -140,6 +140,7 @@ func TestBasic(t *testing.T) {
testRaw(t, setBool, `[null]`, ``, `0`, nil) testRaw(t, setBool, `[null]`, ``, `0`, nil)
testRaw(t, setString, `{"arr":[1]}`, ``, `arr.-1`, 1) testRaw(t, setString, `{"arr":[1]}`, ``, `arr.-1`, 1)
testRaw(t, setString, `{"a":"\\"}`, ``, `a`, "\\") testRaw(t, setString, `{"a":"\\"}`, ``, `a`, "\\")
testRaw(t, setString, `{"a":"C:\\Windows\\System32"}`, ``, `a`, `C:\Windows\System32`)
} }
func TestDelete(t *testing.T) { func TestDelete(t *testing.T) {