Fix division by zero in polar color space unpremultiply when alpha is 0#1195
Closed
queelius wants to merge 1 commit intoparcel-bundler:masterfrom
Closed
Fix division by zero in polar color space unpremultiply when alpha is 0#1195queelius wants to merge 1 commit intoparcel-bundler:masterfrom
queelius wants to merge 1 commit intoparcel-bundler:masterfrom
Conversation
The polar_premultiply macro's unpremultiply method was missing a check for alpha != 0.0 before dividing by alpha, causing NaN values to leak into the output when interpolating colors with zero alpha in polar color spaces (HSL, HWB, LCH, OKLCH) via color-mix(). The rectangular_premultiply macro already had this guard. This commit adds the same check to polar_premultiply to match. Fixes parcel-bundler#1194 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a division-by-zero bug in polar color-space interpolation when alpha == 0.0, preventing NaN components from leaking into serialized CSS (e.g. none in oklch() / lch() output) during color-mix().
Changes:
- Add an
alpha != 0.0guard in thepolar_premultiplymacro’sunpremultiplymethod (matchingrectangular_premultiplybehavior). - Add regression tests covering
color-mix()with zero-alpha inputs in HSL, HWB, LCH, and OKLCH.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/values/color.rs |
Prevents division by zero during unpremultiply for polar color spaces when alpha is zero. |
src/lib.rs |
Adds regression tests to ensure zero-alpha color-mix() in polar spaces doesn’t serialize NaN/none. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
Closing this to keep your queue clean. Happy to reopen if useful, or feel free to pick up any of it. Thanks! |
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.
Summary
polar_premultiplymacro'sunpremultiplymethod whenalpha == 0.0&& self.alpha != 0.0guard to match the existingrectangular_premultiplybehaviorcolor-mix()with zero-alpha colors in all four polar color spaces (HSL, HWB, LCH, OKLCH)Problem
When using
color-mix()to interpolate colors with zero alpha in polar color spaces (HSL, HWB, LCH, OKLCH), theunpremultiplystep divides byalpha(which is 0), producingNaNvalues. TheseNaNvalues then serialize asnonein the CSS output.For example:
The
rectangular_premultiplymacro already guards against this withself.alpha != 0.0, butpolar_premultiplywas missing the check.Test plan
color-mix()with zero-alpha in HSL, HWB, LCH, and OKLCHcargo test- 117 tests + doc tests)Fixes #1194
Generated with Claude Code