Discard invalid color declarations instead of dropping the property (…#1065
Open
StefanoD wants to merge 1 commit into
Open
Discard invalid color declarations instead of dropping the property (…#1065StefanoD wants to merge 1 commit into
StefanoD wants to merge 1 commit into
Conversation
…inebender#914) Figma exports SVGs with a dual stroke definition: a valid hex fallback followed by a wide-gamut value, e.g. style="stroke:#FAFAFA;stroke:color(display-p3 0.9804 0.9804 0.9804);" When splitting a `style` attribute (or applying a CSS rule), the last declaration for a property always won, regardless of validity. The unsupported `color(display-p3 ...)` value thus overwrote the valid `#FAFAFA` one, and since stroke parsing later fell back to "no stroke", the element was rendered invisibly. Per CSS error recovery, a declaration with an invalid value must be discarded so a previously declared valid value (or the presentation attribute) is kept. Validate the color-bearing presentation properties (`fill`, `stroke`, `color`, `flood-color`, `lighting-color`, `stop-color`) before inserting them and skip invalid declarations. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82ea3e6 to
12949e8
Compare
nicoburns
requested changes
Jun 14, 2026
nicoburns
left a comment
Collaborator
There was a problem hiding this comment.
The concept of discarding invalid declarations so that earlier valid ones take effect seems correct, but this implementation looks like it ends up parsing the declaration twice. Could we make use of Option<T> so that it only needs to be parsed once?
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.
Fixes #914.
Figma exports SVGs with a dual stroke definition: a valid hex fallback
followed by a wide-gamut value, e.g.
When splitting a
styleattribute (or applying a CSS rule), the lastdeclaration for a property always won, regardless of validity. The
unsupported
color(display-p3 ...)value overwrote the valid#FAFAFAone, and since stroke parsing later falls back to "no stroke", the
element was rendered invisibly.
Per CSS error recovery, a declaration with an invalid value must be
discarded so a previously declared valid value (or the presentation
attribute) is kept. This PR validates the color-bearing presentation
properties (
fill,stroke,color,flood-color,lighting-color,stop-color) before inserting them and skips invalid declarations.Behavior for a single invalid declaration is unchanged (stroke → none,
fill → default/inherited).
Testing
invalid_style_declaration_falls_back_to_valid_one(fails before, passes after).
usvgtest suite passes;cargo buildclean with no new clippy warnings.Generated by Claude