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

array/object comparison is not symmetric #132

Open
davidje13 opened this issue Oct 24, 2021 · 0 comments
Open

array/object comparison is not symmetric #132

davidje13 opened this issue Oct 24, 2021 · 0 comments

Comments

@davidje13
Copy link

Due to the way Arrays are identified, it is possible to construct an object which "looks like" an array, but only when passed as the second argument:

const v1 = ['a', 'b'];
const v2 = { 0: 'a', 1: 'b', 2: 'c', length: 2, constructor: Array };
equal(v1, v2); // = true
equal(v2, v1); // = false

It doesn't seem particularly problematic or risky either way, but the asymmetry of the arguments is surprising.

There is also a similar (related?) issue that any extra properties on an array are not checked:

const v1 = Object.assign(['a', 'b'], { woo: 'hi' });
const v2 = ['a', 'b'];
equal(v1, v2); // = true
equal(v2, v1); // = true

Both of these behaviours diverge from the behaviour of util.isDeepStrictEqual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant