append non-existent array element

This commit is contained in:
Josh Baker 2016-12-12 09:53:56 -07:00
parent af43ab8ae1
commit 6a22caf2fd
2 changed files with 2 additions and 1 deletions

View File

@ -128,7 +128,7 @@ func appendBuild(buf []byte, array bool, paths []pathResult, raw string,
}
if len(paths) > 1 {
n, numeric := atoui(paths[1])
if numeric {
if numeric || (!paths[1].force && paths[1].part == "-1") {
buf = append(buf, '[')
buf = appendRepeat(buf, "null,", n)
buf = appendBuild(buf, true, paths[1:], raw, stringify)

View File

@ -141,6 +141,7 @@ func TestBasic(t *testing.T) {
testRaw(t, setString, `["1234.5"]`, ``, `0`, "1234.5")
testRaw(t, setBool, `[true]`, ``, `0`, true)
testRaw(t, setBool, `[null]`, ``, `0`, nil)
testRaw(t, setString, `{"arr":[1]}`, ``, `arr.-1`, 1)
}
func TestDelete(t *testing.T) {