Repository navigation
css: read a NaN calculation in a color channel as 0, not none
#45971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5165f13
css: fail a percentage calc that cannot be reduced instead of folding…
robobun d634e2b
css: read a NaN calculation in a color channel as 0, not `none`
robobun b5bfff7
css: make the rows for valid values that are not reduced todo tests
robobun 0225708
css: say what each NaN color row is in the test comments
robobun 1382c23
test(css): assert the value as written for a typed @property that is …
robobun 81f197d
Merge remote-tracking branch 'origin/main' into robobun/42f37e50/css-…
robobun f7ecd42
Merge remote-tracking branch 'origin/main' into robobun/42f37e50/css-…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 A stylesheet whose typed
@ propertyinitial-value holds a valid relative color such asoklch(from #ff876a calc(l - .08) c h)now fails the whole bundle; on the base branch it built. RelativeComponentParser::parse_percentage wraps the channel keyword as a Percentage (color.rs:2172), socalc(l - .08)becomes a percentage+number sum thatPercentage::from_calcnow rejects (calc.rs:1615).@ propertyhas no unparsed fallback and error_recovery is never true. Fix: read the keyword as the spec's (l for oklab/oklch, l*100 for lab/lch/hsl/hwb) and scale back, so calc(keyword +/- number) reduces in every percentage-only channel reader;Bun.color()also returns null for these inputs. [also at: src/css/values/calc.rs:1615 - Bundling a stylesheet whose typed@ propertyinitial-value is a valid relative color likehsl(from blue h s calc(l + 20))now fails with "Unexpected token: hsl("; on the base it built.]Why this was flagged
Input:
@ property --p { syntax: "<color>"; inherits: false; initial-value: hsl(from blue h s calc(l + 20)); }or the oklch form above, both valid CSS (css-color-5: thelkeyword is a , Chrome accepts them). The relative arm at color.rs:2169-2183 buildsCalc::Value(Box::new(Percentage { v }))for the keyword (color.rs:2172), soCalc::addat calc.rs:264 callsrhs.into_value()on the Number term, andPercentage::from_calcnow returnsErr(invalid_value)(calc.rs:1615). The literal fallback at color.rs:2009 cannot parse the keyword either, so the color errors. For acolor:declaration this is caught as an unparsed property, but@ propertypropagates the error (src/css/rules/property.rs:141),error_recoveryis only ever false (css_parser.rs:2952), and the stylesheet parse returns Err at css_parser.rs:2627, which the bundler reports as a bundle error. On the base branchfrom_calcfolded the sum toPercentage { v: NaN }, so the rule built (with a wrongnonechannel).Verification:
RelativeComponentParser::parse_percentage(src/css/values/color.rs:2169-2172) wrapslasCalc::Value(Box::new(Percentage { v })).Calc::addat calc.rs:258-265 callsPercentage::from_calc, changed toErr(invalid_value)(calc.rs:1612-1616).PropertyRule::parsehas no fallback at src/css/rules/property.rs:141, anderror_recoveryis only everfalse(css_parser.rs:2952). On the base the same input built.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same root as the thread on #45970: the error comes from
Percentage::from_calc, which is the first commit of this stack.<number>, is css: fold relative colors on the scale of their function, and keep them as written when the fold is not exact #45362 (commit b7ea982).@propertyis css: keep a typed @property initial-value as written when no component matches #45807.I did not copy either into this PR. #45970 now says to land #45807 first, and its tests assert the as-written output for the valid value in a
test.todorow. I leave this thread open for a maintainer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update after 1382c23.
@propertyrows of css: fail a percentage calc that cannot be reduced instead of folding it to NaN #45970 are now onetest.todothat asserts the value as written. On a local merge of this branch with css: read an @property initial-value on the stylesheet's parser, keep an unmatched value as written #45806, that test passes.This thread stays open for a maintainer.