Skip to content

Conversation

@Han5991
Copy link
Contributor

@Han5991 Han5991 commented Nov 19, 2025

util.inspect() was still inserting line breaks when both breakLength and depth were set to Infinity. Grouping logic and the compact
inline heuristics were ignoring the special “no wrapping” intent. This change adds an isUnlimitedDepth() guard so the line-wrapping paths
are skipped when the user explicitly asks for infinite width and depth.

Fixes: #60475

image

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Nov 19, 2025
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.51%. Comparing base (b1e941e) to head (545a24f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60783      +/-   ##
==========================================
+ Coverage   88.50%   88.51%   +0.01%     
==========================================
  Files         703      703              
  Lines      208394   208404      +10     
  Branches    40189    40197       +8     
==========================================
+ Hits       184430   184479      +49     
+ Misses      15965    15925      -40     
- Partials     7999     8000       +1     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 99.67% <100.00%> (+0.06%) ⬆️

... and 27 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.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

The issue is actually that compact does not take into account that breakLength might be infinite. A simpler fix is to just add && !NumberIsFinite(ctx.breakLength) next to https://github.com/nodejs/node/pull/60783/files#diff-ee826b416a72014ac81621cf3ecaeec6adcc40163f60775d157aa94618c80201R2627

That should result in the expected output.

@Han5991 Han5991 requested a review from BridgeAR November 30, 2025 13:35
@Han5991
Copy link
Contributor Author

Han5991 commented Nov 30, 2025

@BridgeAR
Thanks for the pointer! I added the NumberIsFinite(ctx.breakLength) guard to the groupArrayElements call in reduceToSingleString, so breakLength: Infinity
skips compact grouping. Also added a test to ensure arrays stay single-line with breakLength: Infinity even when depth is finite

@Han5991 Han5991 force-pushed the util-inspect-breaklength-infinity branch from 3a818c9 to 2a0a7d5 Compare December 1, 2025 01:44
@Han5991 Han5991 force-pushed the util-inspect-breaklength-infinity branch from 2a0a7d5 to 545a24f Compare December 1, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

util.inspect() ignores breakLength: Infinity when depth: Infinity is also set in some cases

3 participants