forked from mirror/sjson
Merge pull request #24 from Jawshua/string-escaping-failure
Fix backslashes not being escaped correctly
This commit is contained in:
commit
c943cc8c8d
2
sjson.go
2
sjson.go
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue