`entriesEqual` breaks on sets of objects with null prototype
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 112
- Forks
- 45
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 1
Description
The last line of entriesEqual throws the following error in my test cases:
TypeError: Cannot convert object to primitive value
at Array.toString (native)
at Array.sort (native)
[...]
Here is how I can reproduce it with chai:
function getAnimals() {
const duck = Object.create(null);
duck.name = "duck";
const cat = Object.create(null);
cat.name = "cat";
return new Set([duck, cat]);
}
const actual = getAnimals();
const expected = new Set([{name: "duck"}, {name: "cat"}]);
assert.deepEqual(actual, expected);
The error is caused by the fact that the objects with a null prototype cannot be converted to strings implicitly, and the array sort function performs a lexicographical sort on strings so it first tries to convert them to strings.
(Tested on Node 9.4)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the entriesEqual implementation and run the supplied chai reproduction with the null-prototype objects in sets. Trace the final sorting step and verify that assert.deepEqual(actual, expected) completes successfully without the TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100