Skip to content

Commit

Permalink
append non-existent array element
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Dec 12, 2016
1 parent af43ab8 commit 6a22caf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6a22caf

Please sign in to comment.