GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assert,util: fix TypeError on Maps with null keys · nodejs/node@248ff9f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/util
    • comparisons.js
  • test/parallel
    • test-assert-deep.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/util/comparisons.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/comparisons.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,13 @@ function mapObjectEquiv(array, a, b, mode, memo) {
837837
let start = 0;
838838
let end = array.length - 1;
839839
const comparator = mode !== kLoose ? objectComparisonStart : innerDeepEqual;
840-
const extraChecks = mode === kLoose || array.length !== a.size;
841840

842841
for (const { 0: key1, 1: item1 } of a) {
843-
if (extraChecks && (typeof key1 !== 'object' || key1 === null)) {
842+
// Primitive and `null` keys can never match an object key collected in
843+
// `array`, so resolve them directly against `b`. `null` is `typeof
844+
// 'object'`, so without this it would reach the object comparator, which
845+
// reads `key1.constructor` and throws a `TypeError`.
846+
if (typeof key1 !== 'object' || key1 === null) {
844847
if (b.has(key1)) {
845848
if (mode !== kLoose || innerDeepEqual(item1, b.get(key1), mode, memo)) {
846849
continue;
Collapse file

‎test/parallel/test-assert-deep.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ test('es6 Maps and Sets', () => {
421421
new Map([[undefined, null], ['+000', 2n]]),
422422
new Map([[null, undefined], [false, '2']]),
423423
);
424+
// A null key whose value is an object, alongside another object key and a
425+
// matching map size, must not crash the unordered object-key matching (null
426+
// is `typeof 'object'`). Refs: https://github.com/nodejs/node/issues/64433
427+
assertNotDeepOrStrict(
428+
new Map([[null, { v: 1 }], [{ a: 1 }, 1]]),
429+
new Map([[{ b: 2 }, { v: 1 }], [{ a: 1 }, 1]])
430+
);
431+
assertDeepAndStrictEqual(
432+
new Map([[null, { v: 1 }], [{ a: 1 }, 1]]),
433+
new Map([[null, { v: 1 }], [{ a: 1 }, 1]])
434+
);
424435
const xarray = ['x'];
425436
assertDeepAndStrictEqual(
426437
new Set([xarray, ['y']]),

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.