assert,util: fix TypeError on Maps with null keys#64441
Open
bitpshr wants to merge 1 commit into
Open
Conversation
`assert.deepStrictEqual`, `assert.notDeepStrictEqual`, and `util.isDeepStrictEqual` threw a `TypeError` instead of returning a result when one Map had a `null` key with an object value, the other had an object key with a deeply-equal value but no `null` key, and both maps were the same size. In that case `mapObjectEquiv` skipped its primitive and `null` key handling, which was gated on `array.length !== a.size`, and passed the `null` key (which is `typeof 'object'`) to the object comparator. That comparator reads `key.constructor` without a null guard, so it threw. Handle primitive and `null` keys unconditionally, resolving them directly against the other map. Fixes: nodejs#64433 Signed-off-by: Paul Bouchon <mail@bitpshr.net>
ljharb
approved these changes
Jul 12, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64441 +/- ##
=======================================
Coverage 90.25% 90.25%
=======================================
Files 741 741
Lines 241376 241379 +3
Branches 45478 45486 +8
=======================================
+ Hits 217843 217855 +12
+ Misses 15087 15085 -2
+ Partials 8446 8439 -7
🚀 New features to boost your workflow:
|
jasnell
approved these changes
Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64433.
assert.deepStrictEqual,assert.notDeepStrictEqual, andutil.isDeepStrictEqualthrow aTypeErroron Maps with anullkey in a specific shape: one map has anullkey with an object value, the other has an object key with a deeply-equal value but nonullkey, and both maps are the same size.It comes from
mapObjectEquivinlib/internal/util/comparisons.js, which only resolved primitive andnullkeys directly against the other map whenarray.length !== a.size. When the sizes match, thenullkey skipped that and reached the object comparator, which readskey.constructorwith no null guard (andtypeof nullis'object'). It only affects strict mode; loose already handled it and partial uses a different path.The fix handles primitive and
nullkeys unconditionally. I added a regression totest-assert-deep.jscovering both the crashing case and the equal case.