Skip to content
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

Node.js 12.0.0 changes how arrays with symbol properties are compared using deepEqual() #27652

Closed
vkarpov15 opened this issue May 11, 2019 · 2 comments
Labels
assert Issues and PRs related to the assert subsystem. confirmed-bug Issues with confirmed bugs.

Comments

@vkarpov15
Copy link

Hi, it looks like Node 12 changed how arrays are compared with deepEqual(), presumably due to https://github.com/nodejs/node/pull/25008/files . Here's an example of how deepEqual() handles arrays with symbol properties:

const assert = require('assert');

console.log(process.version);

const s = Symbol('foo');

const arr = [];
arr[s] = 42;

assert.deepEqual(arr, []);

Running this script with Node.js 11.9.0 succeeds:

$ ~/Workspace/libs/node-v11.9.0-linux-x64/bin/node test.js 
v11.9.0
$

Running with Node.js 12 fails:

$ ~/Workspace/libs/node-v12.0.0-linux-x64/bin/node test.js 
v12.0.0
assert.js:89
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:

[
  [Symbol(foo)]: 42
]

should equal

[]
$ 

Is this a bug or expected behavior? If so, you should update the legacy mode deepEqual() docs, which explicitly state that symbol properties are ignored.

Related to Automattic/mongoose#7784.

@targos
Copy link
Member

targos commented May 11, 2019

/cc @nodejs/assert @BridgeAR

@targos targos added assert Issues and PRs related to the assert subsystem. v12.x labels May 11, 2019
@BridgeAR
Copy link
Member

This was indeed an unintentional change and I missed that the array optimization currently always gets the symbol properties even though the loose equal comparison should not compare symbol properties. I'll open a PR to fix that.

@BridgeAR BridgeAR added the confirmed-bug Issues with confirmed bugs. label May 11, 2019
BridgeAR added a commit to BridgeAR/node that referenced this issue May 11, 2019
This is the way it's currently documented and that seems appropriate
for loose equal assertions. The change was not intentional.

Fixes: nodejs#27652
@Trott Trott closed this as completed in 3aff264 May 13, 2019
targos pushed a commit that referenced this issue May 14, 2019
This is the way it's currently documented and that seems appropriate
for loose equal assertions. The change was not intentional.

Fixes: #27652

PR-URL: #27653
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. confirmed-bug Issues with confirmed bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants