Skip to content

Commit

Permalink
assert,util: fix commutativity edge case
Browse files Browse the repository at this point in the history
Verify that both objects property keys are enumerable.

Fixes: #37710

PR-URL: #37711
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
BridgeAR authored and danielleadams committed Mar 16, 2021
1 parent 8666d77 commit 4451460
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {
// Cheap key test
let i = 0;
for (; i < aKeys.length; i++) {
if (!ObjectPrototypeHasOwnProperty(val2, aKeys[i])) {
if (!ObjectPrototypePropertyIsEnumerable(val2, aKeys[i])) {
return false;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,3 +1194,13 @@ assert.throws(
Object.setPrototypeOf(b, null);
assertNotDeepOrStrict(a, b, assert.AssertionError);
}

{
// Verify commutativity
// Regression test for https://github.com/nodejs/node/issues/37710
const a = { x: 1 };
const b = { y: 1 };
Object.defineProperty(b, 'x', { value: 1 });

assertNotDeepOrStrict(a, b);
}

0 comments on commit 4451460

Please sign in to comment.