From 6a6e0ec683977106039b733591c14c7c3bd8c88d Mon Sep 17 00:00:00 2001 From: Vigen <47vigen@gmail.com> Date: Sat, 30 Jul 2022 10:48:23 +0430 Subject: [PATCH 1/2] fix apply on undefined values --- packages/collection-diff-apply/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/collection-diff-apply/index.js b/packages/collection-diff-apply/index.js index c5d2c3265..0e80d63e5 100644 --- a/packages/collection-diff-apply/index.js +++ b/packages/collection-diff-apply/index.js @@ -118,6 +118,10 @@ function diffApply(obj, diff, pathConverter) { Array.isArray(subObject) ? subObject.splice(lastProp, 1) : delete subObject[lastProp]; } if (thisOp === REPLACE || thisOp === ADD) { + if (subObject === undefined) { + if (typeof lastProp === "number") subObject = []; + else subObject = {}; + } subObject[lastProp] = thisDiff.value; } From 5ac8ef1d112df5922a2f402f223a553dd3fa1715 Mon Sep 17 00:00:00 2001 From: Vigen <47vigen@gmail.com> Date: Sat, 30 Jul 2022 10:55:43 +0430 Subject: [PATCH 2/2] better check lastProp --- packages/collection-diff-apply/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/collection-diff-apply/index.js b/packages/collection-diff-apply/index.js index 0e80d63e5..bee6798ae 100644 --- a/packages/collection-diff-apply/index.js +++ b/packages/collection-diff-apply/index.js @@ -119,8 +119,8 @@ function diffApply(obj, diff, pathConverter) { } if (thisOp === REPLACE || thisOp === ADD) { if (subObject === undefined) { - if (typeof lastProp === "number") subObject = []; - else subObject = {}; + if (isNaN(lastProp)) subObject = {}; + else subObject = []; } subObject[lastProp] = thisDiff.value; }