Skip to content

fix(inspect): allow single-line format when breakLength is Infinity#64238

Open
hamidrezaghavami wants to merge 2 commits into
nodejs:mainfrom
hamidrezaghavami:fix-inspect-infinity-clean
Open

fix(inspect): allow single-line format when breakLength is Infinity#64238
hamidrezaghavami wants to merge 2 commits into
nodejs:mainfrom
hamidrezaghavami:fix-inspect-infinity-clean

Conversation

@hamidrezaghavami

Copy link
Copy Markdown

Description

When calling util.inspect() with a breakLength configuration explicitly set to Infinity, the internal layout formatting logic should bypass multi-line chunking and formatting constraints entirely, allowing the contents to naturally evaluate on a single line.

Currently, isBelowBreakLength goes through a character length loop calculation even when length checks are logically unnecessary due to the infinite upper bound. This change introduces an explicit early return branch within isBelowBreakLength when ctx.breakLength === Infinity, properly enabling a clean, un-wrapped single-line string formatting mode.

Checklist

  • Core internal utility verification

@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 Jul 1, 2026

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this definitely needs tests to cover the changed behavior. ideally, you'd also provide the tests' output absent this change.

@hamidrezaghavami

Copy link
Copy Markdown
Author

Hello, @ljharb The single-line formatting behaviour when breakLength is set to Infinity is covered in a test case that I have provided.
Behaviour of output for context:
Without this modification, if it causes internal length constraint checks, the output is automatically converted to a multi-line format that spans many lines.
With this modification, multi-line chunking is completely avoided by the internal layout logic, which evaluates the contents into a single line format precisely as anticipated:
"a: 1, b: 2, c: 3, d: 4 }"

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.

3 participants