Fixed bug in deepEqual not handling duplicate fields of an object
This commit is contained in:
parent
54cae20630
commit
d1ac1cb694
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue