Repository navigation
fix(parser): ignore empty declarations in SVG style attributes instead of failing the import - #11185
Merged
Smrtnyk merged 3 commits intoOct 30, 2026
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Contributor
|
Build Stats
|
Member
|
@Smrtnyk can you merge this when you can? |
asturur
approved these changes
Oct 30, 2026
Smrtnyk
approved these changes
Oct 30, 2026
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.
Description
Closes #11184
parseStyleStringonly skipped chunks that were completely empty. A blank declaration, like the one instyle="fill:red; ;", or a whitespace-onlystyle=" ", gets past that check. Thenchunk.split(':')has no value, andvalue.trim()throws. Because this happens during parsing, the wholeloadSVGFromStringcall rejects, not just the element with the blank declaration:Empty declarations are valid CSS and browsers ignore them. The parser used to guard against this (see #2241), but the check was lost.
The fix skips any chunk without a
name:valuepair. That replaces the old!chunkcheck, since an empty chunk has no value either.Tests:
parser.spec.tsfor a style with empty declarations between valid ones, and for a blank style attribute.svg_style_empty_declarations). It uses four shapes whosestyleattributes each contain blank declarations, including one where a declaration after a blank one (the stroke) still has to apply. Without the fix it fails with theTypeErrorabove; with it, it renders as expected.Note: I generated the golden with Playwright's
chromechannel (Chrome 156) on Windows. The CI runner is the Linux headless shell. The case only has solid fills and one stroke, so it should be well within the tolerance, but if CI reports a small diff the golden may need to be regenerated there.In Action
Golden for the new case: red and blue squares and a green circle, all filled through styles with blank declarations, plus an orange circle whose black stroke comes after a blank declaration.