From 65b1cdbae0a9e873a3d2bc4636038423351b794e Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Sun, 27 Sep 2020 18:20:52 +0200 Subject: [PATCH] fix(core): Observable splice index > length (#8900) * fix for splice index > length In javascript you can call splice with an index > length. The result is a push. But when you do that ObservableArray index will be wrong and thus user logic will fail. Example: ```ts // obsarray = [0]; obsarray.splice(2, 0, 1); // this works, the inner array is now [0,1] // however 'change' is called with index = 2 // when the use tries to do obsarray.getItem(eventData.index) -> crash ``` * fix to handle delete too --- packages/core/data/observable-array/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/data/observable-array/index.ts b/packages/core/data/observable-array/index.ts index b7f390cc1..cc026e91e 100644 --- a/packages/core/data/observable-array/index.ts +++ b/packages/core/data/observable-array/index.ts @@ -246,7 +246,7 @@ export class ObservableArray extends Observable { eventName: CHANGE, object: this, action: ChangeType.Splice, - index: start, + index: Math.min(start, this._array.length-1), removed: result, addedCount: this._array.length + result.length - length, });