From d1ac1cb69436eb05252a7a543e9712db77d440bc Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 7 Aug 2018 10:22:55 +0200 Subject: [PATCH] Fixed bug in deepEqual not handling duplicate fields of an object --- src/js/Node.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/js/Node.js b/src/js/Node.js index b2bb455..150d180 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -1318,21 +1318,31 @@ Node.prototype.deepEqual = function (json) { return false; } - if (this.childs.length !== Object.keys(json).length) { - return false; - } - + // TODO: for better efficiency, we could create a property `isDuplicate` on all of the childs + // and keep that up to date. This should make deepEqual about 20% faster. + var props = {}; + var propCount = 0; for (i = 0; i < this.childs.length; i++) { var child = this.childs[i]; + if (!props[child.field]) { + // We can have childs with duplicate field names. + // We take the first, and ignore the others. + props[child.field] = true; + propCount++; - if (!(child.field in json)) { - return false; - } + if (!(child.field in json)) { + return false; + } - if (!child.deepEqual(json[child.field])) { - return false; + if (!child.deepEqual(json[child.field])) { + return false; + } } } + + if (propCount !== Object.keys(json).length) { + return false; + } } else { if (this.value !== json) {