Fix case-insensitive lookup for named CSS colors - #1780
Merged
blikblum merged 1 commit intoAug 25, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #1275.
fillAndStroke("Red", "#900")renders black instead of red, whilefillAndStroke("red", "#900")works. CSS named colors are defined ascase-insensitive keywords, but
_normalizeColorinlib/mixins/color.jslooked up thenamedColorstable 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
namedColorsin_normalizeColor. Spot color lookups (this.spotColors[color]) areleft untouched — those names are caller-registered via
addSpotColor/registerFont-style APIs and are intentionallycase-sensitive.
Test plan
tests/unit/color.spec.jsasserting_normalizeColorresolves"red","Red", and"RED"to the sameRGB value.
npx vitest run tests/unit/color.spec.js— 5/5 pass.npx vitest run(full suite) — same pass/fail counts as onmasterbefore this change (10 pre-existing, unrelated timeouts intests/visual/pdfmake/*, confirmed present on a clean checkout too;all other 525 tests pass).