Skip to content

util: require validateStream === false for the styleText fast path - #67720

Open
GBra-4-669 wants to merge 1 commit into
nodejs:mainfrom
GBra-4-669:util-styletext-validate-stream
Open

GBra-4-669 wants to merge 1 commit into
nodejs:mainfrom
GBra-4-669:util-styletext-validate-stream

Conversation

@GBra-4-669

Copy link
Copy Markdown

styleText('red', 'text', { validateStream: 0 }) returned styled text instead of throwing. The single-format fast path checked validateStream for truthiness before the options were validated so a falsy non-boolean value skipped validation. Require validateStream === false for the fast path: other non-boolean values now reach validateBoolean() and throw ERR_INVALID_ARG_TYPE, false still skips stream validation and null/undefined still select the default.

Updated the benchmark's validateStream axis from [1, 0] to [true, false].

Added cases to test/parallel/test-util-styletext.js, currently failing on main.

Fixes: #67700

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@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 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@araujogui araujogui added the semver-major PRs that contain breaking changes and should be released in the next major version. label Nov 23, 2026

@araujogui araujogui 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.

LGTM. Users relying on an integer validateStream will break, so I'm labeling this as semver-major.

@MikeMcC399

This comment was marked as resolved.

Signed-off-by: GBra 4.669 <35969802+GBra-4-669@users.noreply.github.com>
@GBra-4-669
GBra-4-669 force-pushed the util-styletext-validate-stream branch from 52f4e2c to db83b03 Compare November 26, 2026 22:35
@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 27, 2026
// the high-miss-rate / large-cache scenario (e.g. user-randomised colors).
format: ['red', 'italic', 'invalid', '#ff0000', '#rotating'],
validateStream: [1, 0],
validateStream: [true, false],

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.

I'm almost sure true and false are passed as strings to the benchmark function (unless something has changed recently).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, they are passed as strings, then _parseArgs converts them (benchmark/common.js:121-122) so [true, false] reaches main() as real bools.

Same convention as 42d0e1307 ("benchmark: use boolean options in benchmark tests").

@RafaelGSS

Copy link
Copy Markdown
Member

Honestly, that would be better solved without a semver major change.

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 27, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.51%. Comparing base (b663e55) to head (db83b03).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67720   +/-   ##
=======================================
  Coverage   90.51%   90.51%           
=======================================
  Files         805      805           
  Lines      285786   285786           
  Branches    55171    55178    +7     
=======================================
+ Hits       258669   258673    +4     
- Misses      17207    17216    +9     
+ Partials     9910     9897   -13     
Files with missing lines Coverage Δ
lib/util.js 100.00% <100.00%> (ø)

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@araujogui

Copy link
Copy Markdown
Member

Honestly, that would be better solved without a semver major change.

are you suggesting casting integers to boolean or vice-versa?

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. semver-major PRs that contain breaking changes and should be released in the next major version. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

styleText fast path bypasses options and options.validateStream validation

6 participants