Fix jsonEquals() bug: actually compare the properties

This commit is contained in:
tophf 2015-08-07 16:48:17 +03:00
parent 21a138029d
commit a9ff8c14f3

View File

@ -389,38 +389,31 @@ function codeIsEqual(a, b) {
} }
function jsonEquals(a, b, property) { function jsonEquals(a, b, property) {
var type = getType(a[property]); var aProp = a[property], typeA = getType(aProp);
var typeB = getType(b[property]); var bProp = b[property], typeB = getType(bProp);
if (type != typeB) { if (typeA != typeB) {
// consider empty arrays equivalent to lack of property // consider empty arrays equivalent to lack of property
if ((type == "undefined" || (type == "array" && a[property].length == 0)) && (typeB == "undefined" || (typeB == "array" && b[property].length == 0))) { if ((typeA == "undefined" || (typeA == "array" && aProp.length == 0)) && (typeB == "undefined" || (typeB == "array" && bProp.length == 0))) {
return true; return true;
} }
return false; return false;
} }
if (type == "undefined") { if (typeA == "undefined") {
return true; return true;
} }
if (type == "array") { if (typeA == "array") {
if (a[property].length != b[property].length) { if (aProp.length != bProp.length) {
return false; return false;
} }
for (var i = 0; i < a.length; i++) { for (var i = 0; i < aProp.length; i++) {
var found = false; if (bProp.indexOf(aProp[i]) == -1) {
for (var j = 0; j < b.length; j++) {
if (a[i] == b[j]) {
found = true;
break;
}
}
if (!found) {
return false; return false;
} }
} }
return true; return true;
} }
if (type == "string") { if (typeA == "string") {
return a[property] == b[property]; return aProp == bProp;
} }
} }