Skip to content

fix: color contrast fails for oklch and oklab with none#4959

Merged
chutchins25 merged 11 commits intodevelopfrom
4894-color-none-fix
Dec 16, 2025
Merged

fix: color contrast fails for oklch and oklab with none#4959
chutchins25 merged 11 commits intodevelopfrom
4894-color-none-fix

Conversation

@chutchins25
Copy link
Copy Markdown
Contributor

Adds error handling for color-contrast checks. This now will report an 'incomplete' error message when the foreground and/or background color strings were not able to be parsed into an actual color.

Tests also verify that text-shadow color is handled should that occur.

fixes: 4894


Developer Notes:
I was not able to have a test case trigger the colorParse error on text-shadow colorParse issues. This case was getting caught already but in the form of the 'complexTextShadows' error.

@chutchins25 chutchins25 requested a review from straker December 5, 2025 15:44
@chutchins25 chutchins25 requested a review from a team as a code owner December 5, 2025 15:44
Copilot AI review requested due to automatic review settings December 5, 2025 15:44
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 5, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where color contrast checks fail when encountering OKLCH or OKLAB colors with none values. The fix adds error handling to gracefully report parsing failures as incomplete results rather than crashing the check.

  • Wraps color parsing operations in try-catch blocks to handle parsing errors
  • Updates the Color class to throw errors with structured cause information
  • Adds new "colorParse" message key to report unparseable color strings across all locales

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/commons/color/color.js Enhanced error throwing to include cause with color string value
lib/commons/color/get-foreground-color.js Added try-catch to handle foreground color parsing failures
lib/commons/color/get-background-color.js Added try-catch to handle background color parsing failures
lib/checks/color/color-contrast-evaluate.js Added logic to detect and report colorParse errors from incomplete data
lib/checks/color/color-contrast.json Added colorParse error message template
lib/checks/color/color-contrast-enhanced.json Added colorParse error message template
locales/_template.json Added colorParse error message template to both color-contrast and color-contrast-enhanced
test/checks/color/color-contrast.js Added three test cases validating error handling for unparseable colors in foreground, background, and text-shadow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

straker
straker previously requested changes Dec 8, 2025
Copy link
Copy Markdown
Contributor

@straker straker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first pass. Other than the comments below, we'll also want to add integration tests that show that the rule itself returns incomplete for the bad color parse. The way that file works is you add the HTML to the .html file that will produce the error and give it an ID. Then in the companion .json file you add the ID to the appropriate result type (in this case incomplete array). We typically try to group the HTML code by type, so you can add the new HTML right after the #canttell20 elements.

@chutchins25 chutchins25 requested a review from straker December 15, 2025 14:11
@straker straker dismissed their stale review December 15, 2025 16:30

Resolved

Copy link
Copy Markdown
Contributor

@straker straker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Adding incompleteData to the Color class simplifies the handling of the error. Otherwise we'd have to find every instance of new Color throughout all the nested background / foreground functions that may already have incompleteData and catch and handle the error in them.

@straker
Copy link
Copy Markdown
Contributor

straker commented Dec 15, 2025

Would like @dbjorge or @WilcoFiers to review as well

@chutchins25
Copy link
Copy Markdown
Contributor Author

Would like @dbjorge or @WilcoFiers to review as well

Do you think they may have opinions on the introduction of the incompleteData to color.js? I know when I presented this idea to you, you had mentioned they may have historical reasoning to either do so or not do so.

I had bounced this off them in Slack and they seemed ok with it at a glance and deferred to your judgement.

I am ok either way. Just making sure you are.

@chutchins25 chutchins25 merged commit 8f249fd into develop Dec 16, 2025
24 checks passed
@chutchins25 chutchins25 deleted the 4894-color-none-fix branch December 16, 2025 15:37
This was referenced Jan 5, 2026
WilcoFiers added a commit that referenced this pull request Jan 6, 2026
###
[4.11.1](v4.11.0...v4.11.1)
(2026-01-06)

### Bug Fixes

- allow shadow roots in axe.run contexts
([#4952](#4952))
([d4aee16](d4aee16)),
closes [#4941](#4941)
- color contrast fails for oklch and oklab with none
([#4959](#4959))
([8f249fd](8f249fd))
- **color-contrast:** do not incomplete on textarea
([#4968](#4968))
([d271788](d271788)),
closes [#4947](#4947)
- **commons/color:** Match browser behavior for out-of-gamut oklch
colors ([#4908](#4908))
([5036be8](5036be8))
- don't runs rules that select `html` on nested `html` elements
([#4969](#4969))
([1e9a5c3](1e9a5c3))
- replaced luminance threshold constant 0.03928 with 0.04045
([#4934](#4934))
([316967d](316967d)),
closes [#4933](#4933)
- **rgaa:** adjust mapping of aria-hidden-\* and valid-lang
([#4935](#4935))
([77571f2](77571f2))
- **valid-lang:** update valid-langs for newer language codes
([#4966](#4966))
([c3f5446](c3f5446)),
closes [#4963](#4963)

This PR was opened by a robot 🤖 🎉
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.

Graceful handling of color contrast check fails for oklch and oklab with none

4 participants