Skip to content

[Bug]: SVG Parsing ignores multiple style tags #10683

@Chicken-3001

Description

@Chicken-3001

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have read and followed the Issue Tracker Guide
  • I have searched and referenced existing issues and discussions
  • I am filing a BUG report.
  • I have managed to reproduce the bug after upgrading to the latest version
  • I have created an accurate and minimal reproduction

Version

6.6.4

In What environments are you experiencing the problem?

Chrome

Node Version (if applicable)

None

Link To Reproduction

https://codesandbox.io/p/devbox/fabric-vanillajs-sandbox-forked-qphrsv

Steps To Reproduce

  1. Parse an SVG document with at least 2 non-empty <style> tags.

Expected Behavior

When parsing an SVG document, the rules in every <style> tag will be applied to the resulting Fabric.js objects.

For example, parsing the SVG:

<svg xmlns="http://www.w3.org/2000/svg">
  <style>
    .blue { fill: blue; }
  </style>
  <style>
    .red { fill: red; }
  </style>
  <circle class="blue" r="45" cx="50" cy="50"></circle>
  <circle class="red" r="45" cx="150" cy="50"></circle>
</svg>

should result in the following Fabric.js circles (when rendered on a canvas):

Image

Actual Behavior

Any rules outside of the first <style> tag don't appear in the resulting Fabric.js objects.

For example, parsing the SVG:

<svg xmlns="http://www.w3.org/2000/svg">
  <style>
    .blue { fill: blue; }
  </style>
  <style>
    .red { fill: red; }
  </style>
  <circle class="blue" r="45" cx="50" cy="50"></circle>
  <circle class="red" r="45" cx="150" cy="50"></circle>
</svg>

results in the following Fabric.js circles (when rendered on a canvas)::

Image

The .red class defined in the second <style> tag is ignored.

Error Message & Stack Trace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions