terminal-code icon indicating copy to clipboard operation
terminal-code copied to clipboard

[zenbu-bot test] parseHex returns null for 3-digit hex colors like #fff

Open RobPruzan opened this issue 1 month ago • 3 comments

This is a test of Zenbu bot by a maintainer. It will be closed after the check.

parseHex in src/theme/color.ts only accepts the six-digit form. parseHex("#fff") returns null instead of [255, 255, 255], so a theme file that uses the 3-digit shorthand loses that color.

RobPruzan avatar Oct 30 '26 12:10 RobPruzan

parseHex returns null for 3-digit hex colors such as #fff

Problem

parseHex in src/theme/color.ts accepts only 6-digit hex values. parseHex("#fff") returns null, not [255, 255, 255]. A theme color written in 3-digit shorthand is dropped.

Steps to reproduce

  1. Run npx tsc -p tsconfig.json and node scripts/write-cjs-boundary.js.
  2. In Node, call require("./dist/theme/color.js").parseHex("#fff").
  3. Or run node --test test/parse-hex-shorthand.test.js.

Expected

parseHex(\"#fff\") returns [255, 255, 255], and parseHex(\"#f80\") returns [255, 136, 0].

Actual

parseHex(\"#fff\") returns null.

Cause

parseHex in src/theme/color.ts matches /^#?([0-9a-f]{6})$/i. The regex accepts exactly 6 hex digits, so a 3-digit value fails the match and the function returns null.

Evidence

Reproduced on main@5b1a5e6 by the test test/parse-hex-shorthand.test.js:

- ]
  code: 'ERR_ASSERTION'
  name: 'AssertionError'
  expected:
    0: 255
    1: 255
    2: 255
  actual: ~
  operator: 'deepStrictEqual'
  stack: |-
    TestContext.<anonymous> (/home/zenbu/base/test/parse-hex-shorthand.test.js:7:10)
    Test.runInAsyncScope (node:async_hooks:214:14)
    Test.run (node:internal/test_runner/test:1047:25)
    Test.start (node:internal/test_runner/test:944:17)
    startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17)
  ...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 98.349968
Extra information
Job 41059958940-1
Handler issue.enhance
Classification bug
Sandbox docker · linux
Test command npx tsc -p tsconfig.json > /dev/null; node scripts/write-cjs-boundary.js && node --test test/parse-hex-shorthand.test.js
Log GitHub Actions run

zenbu-bot[bot] avatar Oct 30 '26 12:10 zenbu-bot[bot]

@zenbu-bot please try again (bot config updated)

RobPruzan avatar Oct 30 '26 13:10 RobPruzan

Zenbu bot test complete.

RobPruzan avatar Oct 30 '26 13:10 RobPruzan