From 051af16d401a2e496180f4be74be4ceedf348d97 Mon Sep 17 00:00:00 2001 From: Jonathan Schroeder Date: Tue, 3 Jul 2018 21:32:43 -0400 Subject: [PATCH] Fix incorrect handling of backslash at end of strings --- sjson.go | 2 +- sjson_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sjson.go b/sjson.go index 7f1d358..ec4b907 100644 --- a/sjson.go +++ b/sjson.go @@ -100,7 +100,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 a7a8f7e..ed9d909 100644 --- a/sjson_test.go +++ b/sjson_test.go @@ -142,6 +142,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) {