Skip to content

util: allow single-line format when break length is infinite - #64238

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
hamidrezaghavami:fix-inspect-infinity-clean
Aug 24, 2026
Merged

util: allow single-line format when break length is infinite#64238
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
hamidrezaghavami:fix-inspect-infinity-clean

Conversation

@hamidrezaghavami

Copy link
Copy Markdown
Contributor

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
Contributor 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 }"

Comment thread test/parallel/test-util-inspect.js Outdated
@hamidrezaghavami
hamidrezaghavami force-pushed the fix-inspect-infinity-clean branch 6 times, most recently from 038a50a to b91c45e Compare July 5, 2026 21:36
Comment thread test/parallel/test-util-inspect.js Outdated
@hamidrezaghavami
hamidrezaghavami force-pushed the fix-inspect-infinity-clean branch 2 times, most recently from 31523f9 to 3060df3 Compare July 6, 2026 07:06
@hamidrezaghavami
hamidrezaghavami requested a review from a team as a code owner July 6, 2026 07:06
@hamidrezaghavami
hamidrezaghavami force-pushed the fix-inspect-infinity-clean branch 3 times, most recently from ede2dd7 to 34da682 Compare July 6, 2026 08:48
@hamidrezaghavami

Copy link
Copy Markdown
Contributor Author

@ljharb All formatting, linting, and core test suites are now fully passing (29/30 checks successful). The single remaining check (test-macOS) failed on an unrelated debugger timeout (test-debugger-exceptions.js 15000ms exceeded), which appears to be a macOS CI runner flake. Could you please re-run that failed macOS job when you have a moment to review?
Thank you!

@ljharb

ljharb commented Jul 6, 2026

Copy link
Copy Markdown
Member

@hamidrezaghavami again, your test case already passes, so it's not a regression test.

@hamidrezaghavami

Copy link
Copy Markdown
Contributor Author

@ljharb To clarify my intent: this patch is a performance early exit fast path inside isBelowBreakLength when breakLength === Infinity, avoiding unnecessary string width calculation loops. Because observable output is identical to main, standard tests pass on both branches. Should we label/track this strictly as a performance optimization/cleanup rather than a bug fix?

@ljharb

ljharb commented Jul 6, 2026

Copy link
Copy Markdown
Member

ahh ok, that wasn't clear to me before

Comment thread test/parallel/test-util-inspect.js Outdated
@hamidrezaghavami
hamidrezaghavami force-pushed the fix-inspect-infinity-clean branch from 34da682 to 31719ca Compare July 6, 2026 19:20
Signed-off-by: Hamid Reza Ghavami <hamidr.ghavami@gmail.com>
@hamidrezaghavami
hamidrezaghavami force-pushed the fix-inspect-infinity-clean branch from 31719ca to a881d0e Compare July 6, 2026 20:56
@hamidrezaghavami

Copy link
Copy Markdown
Contributor Author

@ljharb The CI checks are fully green! I had to force-push one last time to shorten the test string to pass the 80-character max-len linter rule. Could you re-approve when you have a moment, so we can get this merged?
Thank you

@juanarbol juanarbol added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 17, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 17, 2026
@nodejs-github-bot

This comment was marked as resolved.

@hamidrezaghavami

Copy link
Copy Markdown
Contributor Author

Hey team! Just checking in on this. It looks like it has all necessary approvals, but the checks are failing on some unrelated flaky tests. Could a maintainer please help re-run the CI or let me know if any further action is needed? Thanks!

@nodejs-github-bot

This comment was marked as outdated.

@trivikr trivikr added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Aug 22, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr changed the title fix(inspect): allow single-line format when breakLength is Infinity util: allow single-line format when break length is infinite Aug 24, 2026
@trivikr trivikr added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 24, 2026
@nodejs-github-bot
nodejs-github-bot merged commit f509cf1 into nodejs:main Aug 24, 2026
75 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in f509cf1

@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. 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.

5 participants