Skip to content

Commit

Permalink
Add multipassCount to info object passed to the plugins.
Browse files Browse the repository at this point in the history
Use info object to skip subsequent passes in prefixIds plugin to prevent unintended, multiple prefixing.
  • Loading branch information
strarsis authored and GreLI committed Oct 29, 2019
1 parent 67be534 commit 71c7fe7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/svgo.js 100644 → 100755
Expand Up @@ -38,6 +38,7 @@ SVGO.prototype.optimize = function(svgstr, info) {
return;
}

info.multipassCount = counter;
if (++counter < maxPassCount && svgjs.data.length < prevResultSize) {
prevResultSize = svgjs.data.length;
this._optimizeOnce(svgjs.data, info, optimizeOnceCallback);
Expand Down
5 changes: 5 additions & 0 deletions plugins/prefixIds.js 100644 → 100755
Expand Up @@ -125,6 +125,11 @@ var addPrefixToUrlAttr = function(attr) {
*/
exports.fn = function(node, opts, extra) {

// skip subsequent passes when multipass is used
if(extra.multipassCount && extra.multipassCount > 0) {
return node;
}

// prefix, from file name or option
var prefix = 'prefix';
if (opts.prefix) {
Expand Down

0 comments on commit 71c7fe7

Please sign in to comment.