Skip to content

fix: Handle calc() with number type in CSS position checking#494

Merged
ylafon merged 1 commit intomainfrom
fix-calc-number-getlength
Mar 18, 2026
Merged

fix: Handle calc() with number type in CSS position checking#494
ylafon merged 1 commit intomainfrom
fix-calc-number-getlength

Conversation

@sideshowbarker
Copy link
Member

@sideshowbarker sideshowbarker commented Mar 17, 2026

Bug: A conic-gradient() position containing a calc() that resolves to a number causes a ClassCastException to be thrown.

Cause: CssCalc.getLength() only handled computed_type == CSS_LENGTH. When CssBackgroundPosition.checkSyntax() calls getLength() on a calc with computed_type == CSS_NUMBER, it falls through to the throw.

Fix: Delegate to the inner value's getLength() when computed_type is CSS_NUMBER, matching how CssNumber.getLength() handles the zero-check.

The exception is reproducible by checking http://loconto.net

Bug: A conic-gradient() position containing a calc() that resolves
to a number causes a ClassCastException to be thrown.

Cause: CssCalc.getLength() only handled computed_type == CSS_LENGTH.
When CssBackgroundPosition.checkSyntax() calls getLength() on a
calc with computed_type == CSS_NUMBER, it falls through to the throw.

Fix: Delegate to the inner value’s getLength() when computed_type is
CSS_NUMBER, matching how CssNumber.getLength() handles the zero-check.
@ylafon
Copy link
Member

ylafon commented Mar 18, 2026

Good catch, I'll add other types where zero is a valid entry

@ylafon ylafon merged commit b5709a1 into main Mar 18, 2026
1 check passed
@ylafon ylafon deleted the fix-calc-number-getlength branch March 19, 2026 17:25
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.

2 participants