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

Incorrect hash for array with multiple elements that refer to the same object #78

Open
everhardt opened this issue May 3, 2019 · 5 comments

Comments

@everhardt
Copy link

I would expect objectHash(b) === objectHash(c) for

const a = [1, 2];
const b = [[1, 2], [1, 2]];
const c = [a, a];

That's not the case. See https://codepen.io/everhardt/pen/PvYPvp for an example.

@addaleax
Copy link
Collaborator

addaleax commented May 3, 2019

This is intentional – b[0] !== b[1] but c[0] === c[1], so the objects are considered different. I’d like to avoid making breaking changes to this project, and this would definitely be a breaking change.

@everhardt
Copy link
Author

Maybe an option flag respectReferences defaulting to true could be an option? Right now I resort to JSON.parse(JSON.stringify(object)), but that's a bit expensive.

@addaleax
Copy link
Collaborator

addaleax commented May 3, 2019

@everhardt It’s not trivial to implement this in a way so that this still works for objects with circular references – but yes, a PR would be welcome.

@everhardt
Copy link
Author

everhardt commented May 3, 2019 via email

@h0od
Copy link

h0od commented Feb 15, 2023

This issue made me leave this lib in favor for node-object-hash instead, which doesn't have this issue.

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

3 participants