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

fix: Objects without prototype are now properly stringified #64

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

Lu-Ks
Copy link
Contributor

@Lu-Ks Lu-Ks commented Oct 15, 2024

Hey,

I recently discovered that I was using the same key for different object shapes. Upon further investigation, I realized that the object I was attempting to hash did not have prototypes. Following the package workflow, I found that all these objects are hashed using a fallback value <:unknonw>:unknown. These objects may still contain data despite not having prototypes.

Example :

import { hasher } from "node-object-hash";

const hashSortCoerce = hasher({
  sort: true,
  coerce: false,
  alg: "md5",
});

const obj0 = Object.create(null);
console.log(hashSortCoerce.hash(obj0)); // 9e6a14d0fc429751a97d11e74803128e

const obj1 = Object.create(null);
obj1.name = "something";
console.log(obj1); // { name: "something" }
console.log(hashSortCoerce.hash(obj1)); // 9e6a14d0fc429751a97d11e74803128e

const obj2 = Object.create(null);
obj2.name = "else";
console.log(obj2); // { name: "else" }
console.log(hashSortCoerce.hash(obj2)); // 9e6a14d0fc429751a97d11e74803128e

I resolved the issue on my end by wrapping the objects with prototypes, but I believe others might encounter the same problem, which is why I submitted this PR.

Thanks 😃

@Lu-Ks Lu-Ks requested a review from SkeLLLa as a code owner October 15, 2024 13:16
@SkeLLLa
Copy link
Owner

SkeLLLa commented Oct 15, 2024

Thanks for PR. I guess I'll need to update those pipelines first, since they a outdated as hell :).

@SkeLLLa SkeLLLa merged commit a6d1c08 into SkeLLLa:master Dec 17, 2024
1 check passed
Copy link

🎉 This PR is included in version 3.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants