Skip to content

fix(color): don't throw on empty computed color (AXE-3861)#268

Open
Aaryan430 wants to merge 1 commit into
mainfrom
fix/AXE-3861-color-parse-empty-guard
Open

fix(color): don't throw on empty computed color (AXE-3861)#268
Aaryan430 wants to merge 1 commit into
mainfrom
fix/AXE-3861-color-parse-empty-guard

Conversation

@Aaryan430

Copy link
Copy Markdown
Collaborator

What

Guard Color.parseString so a blank / non-string input returns transparent instead of throwing.

Why (AXE-3861)

On a mutation re-scan (SPA) or when walking a <template>/shadow/inert subtree, getComputedStyle(node).getPropertyValue('background-color') returns "" for a detached / non-rendered node. colorjs.io throws Empty color reference on that, which color.js rethrows as Unable to parse color "". That exception is uncaught in the in-page Type-B collection path (a11y-engine-core custom-element-handlers), so it aborts the entire Type-B data collection for the page and cascades to subsequent Workflow-Analyser steps.

Reproduced end-to-end:

  • new Colorjs('') → throws Empty color reference; rgba(0,0,0,0) / transparent / valid colors parse fine.
  • getComputedStyle(detachedNode).getPropertyValue('background-color')"" (attached nodes always return a real value).

Historically this signature spans engine 6.3.46.4.5 across WS / WA / AUT — it's a long-standing latent crash, not a regression.

Fix

parseString: blank / non-string → transparent (0,0,0,0), no throw. Tagged // [a11y-rule-color-contrast]:.

Accuracy

No element a rule actually scores changes verdict: the guard only fires on empty, and empty only occurs for non-rendered nodes (proven). color-contrast gates on isVisibleOnScreen before reading styles, so it never feeds an empty color to the parser. Genuinely-indeterminate-but-rendered backgrounds (image/gradient/obscured) go through the existing incompleteData path and are untouched.

Tests

Adds parseString specs for empty / whitespace / non-string. Full color suite passes (59/59) after grunt build.

Jira: AXE-3861

🤖 Generated with Claude Code

A detached/inert node (mutation re-scan, or a <template>/shadow subtree)
yields an empty computed *-color. colorjs throws "Empty color reference"
on it, and that uncaught abort takes down the whole in-page Type-B data
collection (and cascades to subsequent Workflow-Analyser steps).

Guard parseString: treat a blank/non-string value as transparent instead
of throwing. Genuinely-transparent colors (rgba(0,0,0,0)) still parse
normally; only empty (== a non-rendered node) is short-circuited, so no
element that a rule actually scores changes verdict.

Adds parseString specs for empty / whitespace / non-string input.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant