Skip to content

Revert "assert,util: revert recursive breaking change" #57622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ An alias of [`assert.ok()`][].
<!-- YAML
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57622
description: Recursion now stops when either side encounters a circular
reference.
- version:
- v22.2.0
- v20.15.0
Expand Down Expand Up @@ -632,7 +636,7 @@ are also recursively evaluated by the following rules.
* [Object wrappers][] are compared both as objects and unwrapped values.
* `Object` properties are compared unordered.
* {Map} keys and {Set} items are compared unordered.
* Recursion stops when both sides differ or both sides encounter a circular
* Recursion stops when both sides differ or either side encounters a circular
reference.
* Implementation does not test the [`[[Prototype]]`][prototype-spec] of
objects.
Expand Down Expand Up @@ -743,6 +747,10 @@ parameter is an instance of {Error} then it will be thrown instead of the
<!-- YAML
added: v1.2.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57622
description: Recursion now stops when either side encounters a circular
reference.
- version:
- v22.2.0
- v20.15.0
Expand Down Expand Up @@ -802,7 +810,7 @@ are recursively evaluated also by the following rules.
* [Object wrappers][] are compared both as objects and unwrapped values.
* `Object` properties are compared unordered.
* {Map} keys and {Set} items are compared unordered.
* Recursion stops when both sides differ or both sides encounter a circular
* Recursion stops when both sides differ or either side encounters a circular
reference.
* {WeakMap} and {WeakSet} instances are **not** compared structurally.
They are only equal if they reference the same object. Any comparison between
Expand Down
9 changes: 6 additions & 3 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ function keyCheck(val1, val2, mode, memos, iterationType, keys2) {
if (memos.set === undefined) {
if (memos.deep === false) {
if (memos.a === val1) {
if (memos.b === val2) return true;
return memos.b === val2;
}
if (memos.b === val2) {
return false;
}
memos.c = val1;
memos.d = val2;
Expand All @@ -460,8 +463,8 @@ function keyCheck(val1, val2, mode, memos, iterationType, keys2) {
const originalSize = set.size;
set.add(val1);
set.add(val2);
if (originalSize === set.size) {
return true;
if (originalSize !== set.size - 2) {
return originalSize === set.size;
}

const areEq = objEquiv(val1, val2, mode, keys2, memos, iterationType);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ test('GH-14441. Circular structures should be consistent', () => {
b.a = {};
b.a.a = a;

assertDeepAndStrictEqual(a, b);
assertNotDeepOrStrict(a, b);
}

{
Expand All @@ -571,7 +571,7 @@ test('GH-14441. Circular structures should be consistent', () => {
b.a = b;
const c = {};
c.a = a;
assertDeepAndStrictEqual(b, c);
assertNotDeepOrStrict(b, c);
}

{
Expand All @@ -581,7 +581,7 @@ test('GH-14441. Circular structures should be consistent', () => {
b.add(b);
const c = new Set();
c.add(a);
assertDeepAndStrictEqual(b, c);
assertNotDeepOrStrict(b, c);
}
});

Expand Down
Loading