Skip to content

util: use internal hexSlice directly in util.inspect() - #66974

Open
LiviaMedeiros wants to merge 2 commits into
nodejs:mainfrom
LiviaMedeiros:util-inspect-arraybuffer-hexslice
Open

LiviaMedeiros wants to merge 2 commits into
nodejs:mainfrom
LiviaMedeiros:util-inspect-arraybuffer-hexslice

Conversation

@LiviaMedeiros

Copy link
Copy Markdown
Member

hexSlice, used by util.inspect to format ArrayBuffers, is used in a quite roundabout way: it's wrapped in a function to be set on Buffer.prototype, gets lazily retrieved from the userland-facing prototype, and then uncurried. As a side effect, it's prone to prototype pollution at any moment before a buffer gets inspected.
It would be more straightforward to export it from internal/buffer and use directly.

I'm not sure why it was added with lazy-loading (cc @BridgeAR). If there is a strong reason for that, we can lazy-load it from internal/buffer in the same way.

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Oct 24, 2026
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.58%. Comparing base (b12bad4) to head (7049c38).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66974      +/-   ##
==========================================
- Coverage   92.93%   90.58%   -2.35%     
==========================================
  Files         428      797     +369     
  Lines      195236   278299   +83063     
  Branches    30183    53519   +23336     
==========================================
+ Hits       181442   252109   +70667     
- Misses      13467    16562    +3095     
- Partials      327     9628    +9301     
Files with missing lines Coverage Δ
lib/internal/buffer.js 98.96% <100.00%> (+0.69%) ⬆️
lib/internal/util/inspect.js 97.04% <100.00%> (+20.97%) ⬆️

... and 499 files with indirect coverage changes

🚀 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

buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants