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

Plugin reusePaths implicitly depends on removeXMLProcInst being enabled #1205

Closed
mrackwitz opened this issue Jan 3, 2020 · 2 comments
Closed

Comments

@mrackwitz
Copy link

As the title states, the plugin reusePaths implicitly depends on removeXMLProcInst being enabled. I think this should be at least documented – better fixed.

If a document has an XML processing instruction and the plugin removeXMLProcInst is disabled, then said element is preceding the root element, which the implementation of the reusePaths does not properly handle. This causes the following crash:

TypeError: Cannot read property 'splice' of undefined
    at module.exports.JSAPI.spliceContent (<#REDACTED#>/node_modules/svgo/lib/svgo/jsAPI.js:135:25)
    at Object.exports.fn (<#REDACTED#>/node_modules/svgo/plugins/reusePaths.js:126:19)
    at <#REDACTED#>/node_modules/svgo/lib/svgo/plugins.js:95:27
    at Array.forEach (<anonymous>)
    at full (<#REDACTED#>/node_modules/svgo/lib/svgo/plugins.js:93:13)
    at <#REDACTED#>/node_modules/svgo/lib/svgo/plugins.js:25:24
    at Array.forEach (<anonymous>)
    at module.exports (<#REDACTED#>/node_modules/svgo/lib/svgo/plugins.js:15:13)
    at <#REDACTED#>/node_modules/svgo/lib/svgo.js:70:17
    at SAXParser.sax.onend (<#REDACTED#>/node_modules/svgo/lib/svgo/svg2js.js:169:13)

The problem is here:

svgo/plugins/reusePaths.js

Lines 124 to 126 in 07ca976

const defsTag = new JSAPI({
elem: 'defs', prefix: '', local: 'defs', content: [], attrs: []}, data);
data.content[0].spliceContent(0, 0, defsTag);

@TrySound
Copy link
Member

TrySound commented Sep 1, 2021

Fixed in #1551. Will be released soon.

@TrySound
Copy link
Member

Fixed in https://github.com/svg/svgo/releases/tag/v2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants