From 9b2b8233afc47747162fff90a72b690fd4682a8c Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 5 Sep 2018 12:10:49 +0200 Subject: [PATCH] Fix add in array reusing existing element as oldValue --- src/jsoneditor/immutableJSONPatch.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jsoneditor/immutableJSONPatch.js b/src/jsoneditor/immutableJSONPatch.js index 1e2d2a8..b3a98aa 100644 --- a/src/jsoneditor/immutableJSONPatch.js +++ b/src/jsoneditor/immutableJSONPatch.js @@ -166,7 +166,9 @@ export function add (json, path, value, options) { const resolvedPath = resolvePathIndex(json, path) const parent = getIn(json, initial(path)) const parentIsArray = Array.isArray(parent) - const oldValue = getIn(json, resolvedPath) + const oldValue = parentIsArray + ? undefined + : getIn(json, resolvedPath) const newValue = options.fromJSON(value, oldValue) const updatedJson = parentIsArray