[PR #4] fix(VldArray): correct unique check for objects #3

Closed
opened 2026-03-07 21:30:03 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/ersinkoc/vld/pull/4

State: closed
Merged: Yes


The unique check in VldArray was previously using JSON.stringify to compare objects, which is unreliable because the order of keys in the resulting string is not guaranteed. This could lead to duplicate objects not being detected if their keys were in a different order.

This commit fixes the issue by introducing a stableStringify method that sorts the keys of an object before stringifying it. This ensures that the string representation of an object is always consistent, allowing for reliable duplicate detection.

A new test case has been added to verify the fix and prevent regressions.

**Original Pull Request:** https://github.com/ersinkoc/vld/pull/4 **State:** closed **Merged:** Yes --- The `unique` check in `VldArray` was previously using `JSON.stringify` to compare objects, which is unreliable because the order of keys in the resulting string is not guaranteed. This could lead to duplicate objects not being detected if their keys were in a different order. This commit fixes the issue by introducing a `stableStringify` method that sorts the keys of an object before stringifying it. This ensures that the string representation of an object is always consistent, allowing for reliable duplicate detection. A new test case has been added to verify the fix and prevent regressions.
kerem closed this issue 2026-03-07 21:30:03 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vld#3
No description provided.