mrsum / webpack-svgstore-plugin

Simple svg-sprite creating with webpack
https://www.npmjs.com/package/webpack-svgstore-plugin
200 stars 92 forks source link

Bug in utils:_defs function when encountering a text node #100

Closed kaarholt closed 7 years ago

kaarholt commented 8 years ago

Error occurs in if (child && child.children.length > 0) and if (child && child.attribs.id) when child lacks a children or attribs attr. This occurs (at least) when child is of type 'text'.

quick fix: Changing the problematic lines to if (child && child.children && child.children.length > 0) and if (child && child.attribs && child.attribs.id)

Example input:

<svg xmlns="http://www.w3.org/2000/svg">
  <defs>
    <style>
        /* The content of the style tag is a text-node, and will cause trouble for the _defs function. */
      .myclass {
        /* some styling */
      }
    </style>
  </defs>
  <circle class="myclass" cx="50" cy="50" r="40"/>
</svg>