Skip to content

Commit

Permalink
🐛 fix: Handle comparison between null and another object.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Sep 1, 2020
1 parent f916a1f commit fa1589b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ const deepCompare = (a, b) => {

assert(typeof_a === 'object');

if (_a === null) {
if (_b === null) continue;
return -1;
}

if (_b === null) {
return 1;
}

if (pendingOrChecked.has([_a, _b])) continue;
pendingOrChecked.add([_a, _b]);
pendingOrChecked.add([_b, _a]);
Expand Down
1 change: 1 addition & 0 deletions test/src/deepCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ test(macro, null, undefined, -1);
test(macro, undefined, null, 1);
test(macro, undefined, {}, 1);
test(macro, {}, undefined, -1);
test(macro, null, {}, -1);
test(macro, {}, {}, 0);
test(macro, {}, {a: 1}, -1);
test(macro, {a: 1}, {}, 1);
Expand Down

0 comments on commit fa1589b

Please sign in to comment.