iconfu/svg-inject

Id not converted if reference is in style attribute

iconexperience opened this issue · 3 comments

In the SVG below the second rectangle is not displayed after injection

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,256,256" width="256" height="256">
  <defs>
    <linearGradient x1="0" y1="0" x2="256" y2="0" id="color-1" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="red"/>
      <stop offset="1" stop-color="blue"/>
    </linearGradient>
  </defs>
  <g>
    <rect x="0" y="128" width="256" height="128" fill="url(#color-1)"/>
    <rect x="0" y="0" width="256" height="128" style="fill:url(#color-1)"/>
  </g>
</svg>

The reference inside the style attribute is a perfectly normal way of referencing definitions, as can be seen in https://www.w3.org/TR/SVG11/struct.html#Head

Currently, when making IDs unique, only IDs inside references in the form attrName="url(#myId)" are replaced, but references that are part of the style attribute are ignored. Therefore the ID in the style attribute of the second rect is not converted. As a result the rect has no fill at all.

It should be relatively easy to fix this by taking this in lines 164ff into account.

Just for the record: The Iconic injector and SVGInjector2 both fail on this issue.

Fixed this by adding the style attribute to found IRI referenceable properties if IDs are found. Also, the regex that is used for replacing the IDs now uses the 'global' flag, because the style attribute value can contain multiple references.

fixed in a809db3

will be part of Version 1.1.1