Merge branch 'fix-backslashes' of https://github.com/hypoactiv/sjson into hypoactiv-fix-backslashes

This commit is contained in:
tidwall 2018-09-17 10:17:31 -07:00
commit ce26db08c7
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 {
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
}
}

View File

@ -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) {