do similar array copy at end of recursion

This commit is contained in:
filifa 2024-07-10 23:30:59 -05:00
parent 542c2850a7
commit 8603978c7d
1 changed files with 7 additions and 4 deletions

View File

@ -54,11 +54,14 @@ func patch(obj any, path string, value any) error {
break
}
if idx < len(v) {
v[idx] = value
} else {
v = append(v, value)
if len(v) <= idx {
arr := make([]any, idx+1)
for i, val := range v {
arr[i] = val
}
v = arr
}
v[idx] = value
default:
err = errors.New("couldn't determine type")
}