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

Offen Anfängerfreundlich
#67,700 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@GBra-4-669 arbeitet bereits daran.

Seit 23.11.2026.

  • #67720 von @GBra-4-669 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript, nodejs
Bereich
backend

Rechercherichtung

Der Fehler liegt im styleText-Schnellpfad in lib/util.js, der bei einem einzelnen String-Format früh zurückkehrt und die options- und options.validateStream-Prüfungen überspringt, die der Array-Zweig ausführt. Lies zuerst den Validierungscode in dieser Funktion und vergleiche die beiden Zweige. Reproduziere mit dem Befehl aus dem Issue und füge einen Test in test/parallel/test-util-style-text.js hinzu. Fertig ist, wenn beide Aufrufe bei einem nicht booleschen validateStream ERR_INVALID_ARG_TYPE werfen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
JavaScript
Sterne
124k
Forks
38k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
266

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus nodejs/node

Alle Issues in nodejs/node

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.