deepEqual - hasOwnProperty - false negatives for extended primitives #785
Description
I use another library which appears to extend the Array object with a 'first' function.
When alasql attempts to compare two arrays with deepEqual (x and y), x.first is found during the property loop but when comparing to y, y.first does not pass 'hasOwnProperty' check and deepEqual returns false.
However, x.first property should not even be checked as it is part of prototype or other inheritance.
I think the deepEqual function should be updated to something like:
var deepEqual = function(x, y) {
if (typeof x === "object" && null !== x && (typeof y === "object" && null !== y)) {
if (Object.keys(x).length !== Object.keys(y).length) {
return false;
}
for (var prop in x) {
//only compare property of x if it is belongs to object explicitly
if(x.hasOwnProperty(prop)){
if (y.hasOwnProperty(prop)) {
if (!deepEqual(x[prop], y[prop])) {
return false;
}
} else {
return false;
}
}
}
return true;
} else {
if (x !== y) {
return false;
} else {
return true;
}
}
};
Reproduce failure by attempting the usual multi-sheet xlsx export method and have bootgrid library included. This adds the .first property to Array type and results in the deepEqual failing, leads to array of datasources not being structured properly.
I believe the deepEqual should be altered to do hasOwnProperty check on both test objects even though I also think the Array primitive shouldn't have been adjusted in this way by bootgrid.