Merge branch 'hypoactiv-fix-backslashes'

This commit is contained in:
tidwall 2018-09-17 10:17:46 -07:00
commit 478db4c4dd
2 changed files with 2 additions and 1 deletions

View File

@ -110,7 +110,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] == '"' { if s[i] < ' ' || s[i] > 0x7f || s[i] == '"' || (s[i] == '\\' && i == len(s)-1) {
return true return true
} }
} }

View File

@ -139,6 +139,7 @@ func TestBasic(t *testing.T) {
testRaw(t, setBool, `[true]`, ``, `0`, true) testRaw(t, setBool, `[true]`, ``, `0`, true)
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`, "\\")
} }
func TestDelete(t *testing.T) { func TestDelete(t *testing.T) {