forked from mirror/sjson
append non-existent array element
This commit is contained in:
parent
af43ab8ae1
commit
6a22caf2fd
2
sjson.go
2
sjson.go
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue