diff --git a/sjson.go b/sjson.go index 8213e49..69c40b7 100644 --- a/sjson.go +++ b/sjson.go @@ -110,7 +110,7 @@ func parsePath(path string) (pathResult, error) { func mustMarshalString(s string) bool { 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 } } diff --git a/sjson_test.go b/sjson_test.go index e9f0df0..75f1c4d 100644 --- a/sjson_test.go +++ b/sjson_test.go @@ -139,6 +139,7 @@ func TestBasic(t *testing.T) { testRaw(t, setBool, `[true]`, ``, `0`, true) testRaw(t, setBool, `[null]`, ``, `0`, nil) testRaw(t, setString, `{"arr":[1]}`, ``, `arr.-1`, 1) + testRaw(t, setString, `{"a":"\\"}`, ``, `a`, "\\") } func TestDelete(t *testing.T) {