Skip to content

Fix Buffer deepEqual regression from prototype key comparison - #291

Merged
fatso83 merged 3 commits into
sinonjs:mainfrom
fatso83:buffer-prototype-regression
Mar 16, 2026
Merged

fatso83 merged 3 commits into
sinonjs:mainfrom
fatso83:buffer-prototype-regression

Conversation

@fatso83

@fatso83 fatso83 commented Mar 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a regression test for equal Buffer instances in deepEqual
  • keep prototype enumerable-key comparison for URL-like objects while using own keys for array-like values such as Buffer and typed arrays
  • document in code and commit history that Buffer offset reflects pooled backing-store layout rather than logical content

Test Plan

  • npx mocha ./lib/deep-equal.test.js --grep "returns true for buffers with identical content"
  • npm test -- --grep "array to arguments|arguments to array like object|buffers with identical content|prototype|typed array"
  • npm test
  • node - <<'NODE'
    const assert = require('node:assert');
    const deepEqual = require('./lib/deep-equal');
    assert(deepEqual(Buffer.from('Hello'), Buffer.from('Hello')));
    console.log('buffer reproduction passes');
    NODE

fixes #289 and sinonjs/sinon#2678

fatso83 added 2 commits March 16, 2026 12:27
The prototype-chain comparison added in 3fbe355 made deepEqual read inherited enumerable Buffer accessors such as `offset`.

Two Buffer instances with identical bytes can still have different `offset` values because small Buffers are often views into different positions in the same pooled backing store. That offset is allocator metadata, not part of the logical buffer value.

Keep prototype enumerable-key support for URL-like objects, but use own enumerable keys for array-like values so Buffer equality stays content-based.
@codecov

codecov Bot commented Mar 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5f88086) to head (c17b9aa).
⚠️ Report is 45 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main      #291     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           28        29      +1     
  Lines          532      1624   +1092     
===========================================
+ Hits           532      1624   +1092     
Flag Coverage Δ
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deepEqual is not matching Buffer objects since v9

1 participant