`styleText` fast path bypasses `options` and `options.validateStream` validation

オープン 初心者向け
#67,700 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@GBra-4-669 がすでに取り組んでいます。

2026年11月23日 から。

  • #67720 @GBra-4-669 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, nodejs
領域
backend

調査の方向性

バグは lib/util.js の styleText の高速パスにあります。単一の文字列フォーマットの場合に早期にリターンし、配列ブランチが実行する options と options.validateStream のチェックを飛ばしています。まずその関数の検証コードを読み、2つのブランチを比較してください。issue のコマンドで再現し、test/parallel/test-util-style-text.js にテストを追加してください。両方の呼び出しが、boolean でない validateStream に対して ERR_INVALID_ARG_TYPE をスローすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

util
Version

v26.13.0

Platform
Microsoft Windows NT 10.0.19045.0 x64
Subsystem

util

What steps will reproduce the bug?
node -e "const { styleText } = require('node:util'); const opts = { validateStream: 0 }; console.log(styleText('red', 'text', opts)); styleText(['red'], 'text', opts);"
How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

both styleText('red', 'text', opts) and styleText(['red'], 'text', opts) should throw a TypeError.

according to the documentation, options must be an <Object> and options.validateStream must be a <boolean>. the first call should not bypass validation (https://nodejs.org/api/util.html#utilstyletextformat-text-options)

What do you see instead?

the first call bypasses validation and prints the styled 'text', while the second call throws ERR_INVALID_ARG_TYPE

Additional information

No response

主要言語
JavaScript
スター
124k
フォーク
38k
平均マージ
4日 2時間
マージ済み PR(30日)
266

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nodejs/node のほかの issue

nodejs/node の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。