Skip to content

Fix empty CSS declarations overriding presentation attributes#511

Merged
wieslawsoltes merged 4 commits into
masterfrom
fix/issue-231-empty-style-declarations
May 9, 2026
Merged

Fix empty CSS declarations overriding presentation attributes#511
wieslawsoltes merged 4 commits into
masterfrom
fix/issue-231-empty-style-declarations

Conversation

@wieslawsoltes
Copy link
Copy Markdown
Owner

Pull Request Summary

Summary

Fixes the regression reported in #231 where an SVG presentation attribute such as fill="rgb(0,0,255)" was incorrectly overridden by an invalid empty CSS declaration such as style="fill:;".

Browsers drop declarations with no value and continue applying later valid declarations in the same style block. The Svg.Skia compatibility CSS pipeline was instead forwarding empty declaration values into SvgElement.AddStyle, which allowed the empty inline or stylesheet value to win over a valid presentation attribute and made the fill resolve as black.

This change makes the compatibility pipeline ignore empty or whitespace-only declaration values in both places where CSS declarations are converted into SVG styles:

  • Inline style="..." attributes handled by SvgInlineStyleAttributeParser.
  • Aggregated stylesheet rules handled by SvgCssCompatibilityProcessor.

Valid declarations following an invalid empty declaration are still applied, matching browser behavior. For example, style="fill:;stroke:white" now preserves the element's presentation fill and still applies the inline stroke.

Changes

  • Added a guard in the fast inline style parser so empty values parsed from style="fill:;" are skipped instead of added to the element style map.
  • Added the same guard in the ExCSS fallback path for inline styles, so malformed inline style text that falls back to ExCSS has the same behavior.
  • Added the same guard when stylesheet declarations from <style> elements are materialized for selector application.
  • Added regression coverage for:

Validation

  • dotnet test tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "FullyQualifiedName~SvgDocumentCompatibilityLoaderTests" passed with 37 tests.
  • Prior broader verification on this branch state passed:
    • dotnet build Svg.Skia.slnx -c Release --no-restore
    • dotnet test Svg.Skia.slnx -c Release --no-restore

Notes

dotnet format was attempted during validation, but the formatter host did not return in this worktree for either solution-scoped or project-scoped invocations. The touched source and test changes are minimal and follow the surrounding style.

@wieslawsoltes wieslawsoltes marked this pull request as ready for review May 9, 2026 16:18
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2df855813

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Svg.Custom/Compatibility/SvgInlineStyleAttributeParser.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant