Commit graph

7 commits

Author SHA1 Message Date
Ayush Kumar
ff7b1f0d60
Fix security and performance issues across core, vendor, and examples
Security:
- S2: hexToRgb — explicit typeof branch + padStart(6) for numeric hex inputs;
  makes the numeric-input path intentional and preserves leading zeros
- S3: FORCE_COLOR parsing — guard against NaN propagation when env value is
  non-numeric (e.g. FORCE_COLOR=yes now correctly falls back to level 1)
- S4: _supportsColor — remove side-effecting mutation of module-level
  flagForceColor; effective value is now computed locally, eliminating
  cross-call state corruption in test environments
- S5: applyOptions — change `options.level &&` to `options.level !== undefined`
  so null and NaN are properly rejected instead of silently stored as the level
- S6: browser.js — explicit Number(brand.version) > 93 instead of implicit
  string-to-number coercion for Chromium UA version check

Performance / correctness:
- P1: rainbow.js — replace stateful global-regex test() in loop (which
  misclassified every other non-printable character due to lastIndex advancing)
  with a direct code-point comparison: character < '!' || character > '~'
- P4: stringEncaseCRLFWithFirstIndex — switch from += string concatenation in
  loop to array-of-parts + single join(), reducing intermediate allocations for
  multi-line strings
- P6: builder — detect tagged template literal calls via .raw property and route
  through String.raw(), so chalk.red`hello ${name}` now produces correct output

Tests:
- instance.js: new Chalk({level: null/NaN}) now throws (S5 regression test)
- chalk.js: numeric hex with leading zeros (S2), template literal interpolations
  (P6) covered by new tests; all 35 tests pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 17:21:53 +05:30
Richie Bendall
d798222a5a
Add named exports (#432) 2021-04-17 19:33:03 +07:00
Sindre Sorhus
fa16f4ec37 Require Node.js 12 and move to ESM 2021-04-16 16:22:53 +07:00
Richie Bendall
c0d8e7ed8a
Update test dependencies (#414) 2020-10-03 23:56:24 +02:00
Qix
1f77953f1a Remove the .enabled property in favor of .level (#356) 2019-07-13 12:45:31 +07:00
Sindre Sorhus
655653bb0c Meta tweaks 2019-07-12 14:13:02 +07:00
Tom Sherman
de2f4cd606 Deprecate chalk.constructor() in favor of new chalk.Instance() (#322) 2019-03-12 19:53:03 +07:00