Fixed bug in deepEqual not handling duplicate fields of an object

This commit is contained in:
jos 2018-08-07 10:22:55 +02:00
parent 54cae20630
commit d1ac1cb694
1 changed files with 19 additions and 9 deletions

View File

@ -1318,12 +1318,17 @@ 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;
@ -1334,6 +1339,11 @@ Node.prototype.deepEqual = function (json) {
}
}
}
if (propCount !== Object.keys(json).length) {
return false;
}
}
else {
if (this.value !== json) {
return false;