Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referenced element deleted #303

Open
anvish2 opened this issue Nov 21, 2022 · 4 comments
Open

Referenced element deleted #303

anvish2 opened this issue Nov 21, 2022 · 4 comments

Comments

@anvish2
Copy link

anvish2 commented Nov 21, 2022

scour breaks SVG by deleting referenced element.

Original file:

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs id="defs7285">
  <defs id="defs241">
   <rect id="SVGID_9_" x="423.69" y="131.81" width="350.88" height="413.67"/>
  </defs>
  <clipPath id="SVGID_10_">
   <use id="use245" width="841.89001" height="595.276" xlink:href="#SVGID_9_"/>
  </clipPath>
 </defs>
 <path id="path4615" transform="matrix(1.1464 0 0 1.1712 -486.82 -157.86)" d="m700.52 304.98c13.331-13.353 28.933-28.998 36.853-37.016 2.537-2.568 0.719 99.61 0.719 144.98 0 21.273-13.272 96.323-91.104 58.556 0 0-38.89-13.962-50.247-30.79 2.646 0 5.267-0.169 7.851-0.495 1.183 0.634 2.446 1.226 3.775 1.775 44.896 30.248 71.666 7.998 71.666 7.998 24.757-15.589 28.807-63.192 28.425-69.688" clip-path="url(#SVGID_10_)" fill="#fd0" stroke="#000" stroke-width=".458"/>
</svg>

Compressed file:

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs id="defs7285">
  <clipPath id="SVGID_10_">
   <use id="use245" width="841.89001" height="595.276" xlink:href="#SVGID_9_"/>
  </clipPath>
 </defs>
 <path id="path4615" transform="matrix(1.1464 0 0 1.1712 -486.82 -157.86)" d="m700.52 304.98c13.331-13.353 28.933-28.998 36.853-37.016 2.537-2.568 0.719 99.61 0.719 144.98 0 21.273-13.272 96.323-91.104 58.556 0 0-38.89-13.962-50.247-30.79 2.646 0 5.267-0.169 7.851-0.495 1.183 0.634 2.446 1.226 3.775 1.775 44.896 30.248 71.666 7.998 71.666 7.998 24.757-15.589 28.807-63.192 28.425-69.688" clip-path="url(#SVGID_10_)" fill="#fd0" stroke="#000" stroke-width=".458"/>
</svg>

Note that "defs241" is removed despite "SVGID_9_" being referenced. This leads to broken image.

Workaround is to set "--keep-unreferenced-defs".

@JoKalliauer
Copy link

JoKalliauer commented Nov 23, 2022

I think you might have a malformed file, since you have a defs in defs, don't know if thats allowed.

defs in defs

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs>
  <defs>
   <path id="a" d="M423.69 131.81h350.88v413.67H423.69z"/>
  </defs>
  <clipPath id="b">
   <use width="841.89" height="595.28" xlink:href="#a"/>
  </clipPath>																 
 </defs>
 <path fill="#fd0" stroke="#000" stroke-width=".458" d="M700.52 304.98c13.331-13.353 28.933-28.998 36.853-37.016 2.537-2.568.719 99.61.719 144.98 0 21.273-13.272 96.323-91.104 58.556 0 0-38.89-13.962-50.247-30.79 2.646 0 5.267-.169 7.851-.495 1.183.634 2.446 1.226 3.775 1.775 44.896 30.248 71.666 7.998 71.666 7.998 24.757-15.589 28.807-63.192 28.425-69.688" clip-path="url(#b)" transform="matrix(1.1464 0 0 1.1712 -486.82 -157.86)"/>
</svg>

good file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs>
   <path id="a" d="M423.69 131.81h350.88v413.67H423.69z"/>
  <clipPath id="b">
   <use width="841.89" height="595.28" xlink:href="#a"/>
  </clipPath>																 
 </defs>
 <path fill="#fd0" stroke="#000" stroke-width=".458" d="M700.52 304.98c13.331-13.353 28.933-28.998 36.853-37.016 2.537-2.568.719 99.61.719 144.98 0 21.273-13.272 96.323-91.104 58.556 0 0-38.89-13.962-50.247-30.79 2.646 0 5.267-.169 7.851-.495 1.183.634 2.446 1.226 3.775 1.775 44.896 30.248 71.666 7.998 71.666 7.998 24.757-15.589 28.807-63.192 28.425-69.688" clip-path="url(#b)" transform="matrix(1.1464 0 0 1.1712 -486.82 -157.86)"/>
</svg>

@anvish2
Copy link
Author

anvish2 commented Nov 23, 2022

This was excerpt from a real-world example: https://en.wikipedia.org/wiki/Coat_of_arms_of_Ecuador

@JoKalliauer
Copy link

@MJDSys
Copy link

MJDSys commented Jun 13, 2023

I ran into this issue as well. According to the SVG standard, <defs> can contain structural elements, which includes <defs> (source).

Removing the hierarchy as a workaround does work.

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

No branches or pull requests

3 participants