Skip to content

Fix case-insensitive lookup for named CSS colors - #1780

Merged
blikblum merged 1 commit into
foliojs:masterfrom
PewDieRes:fix-case-insensitive-named-colors
Aug 25, 2026
Merged

Fix case-insensitive lookup for named CSS colors#1780
blikblum merged 1 commit into
foliojs:masterfrom
PewDieRes:fix-case-insensitive-named-colors

Conversation

@PewDieRes

Copy link
Copy Markdown

Problem

Fixes #1275.

fillAndStroke("Red", "#900") renders black instead of red, while
fillAndStroke("red", "#900") works. CSS named colors are defined as
case-insensitive keywords, but _normalizeColor in
lib/mixins/color.js looked up the namedColors table with the raw,
un-lowercased string. Since the table's keys are all lowercase, any
other casing ("Red", "RED", "DarkBlue", ...) silently missed the
lookup and fell through with no color applied.

Fix

Lowercase the color string before indexing into namedColors in
_normalizeColor. Spot color lookups (this.spotColors[color]) are
left untouched — those names are caller-registered via
addSpotColor/registerFont-style APIs and are intentionally
case-sensitive.

Test plan

  • Added a unit test in tests/unit/color.spec.js asserting
    _normalizeColor resolves "red", "Red", and "RED" to the same
    RGB value.
  • npx vitest run tests/unit/color.spec.js — 5/5 pass.
  • npx vitest run (full suite) — same pass/fail counts as on
    master before this change (10 pre-existing, unrelated timeouts in
    tests/visual/pdfmake/*, confirmed present on a clean checkout too;
    all other 525 tests pass).

fillAndStroke/fillColor etc. only matched named colors like "red"
when given in lowercase. CSS color keywords are case-insensitive,
so "Red" or "RED" silently fell through to a null color instead of
being resolved, as reported in foliojs#1275.

Lowercase the lookup key against the namedColors table in
_normalizeColor. Spot color lookups are untouched since those names
are user-registered and intentionally case-sensitive.
@blikblum
blikblum merged commit b87b5ac into foliojs:master Aug 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vector graphics fill attribute doesn't work with pascal cased CSS color names

3 participants