diff --git a/plugins/removeViewBox.js b/plugins/removeViewBox.js index 052642f4a..c062617a9 100644 --- a/plugins/removeViewBox.js +++ b/plugins/removeViewBox.js @@ -23,26 +23,27 @@ var viewBoxElems = ['svg', 'pattern', 'symbol']; * * @author Kir Belevich */ -exports.fn = function(item) { +exports.fn = function (item) { + if ( + item.isElem(viewBoxElems) && + item.hasAttr('viewBox') && + item.hasAttr('width') && + item.hasAttr('height') + ) { + // TODO remove width/height for such case instead + if (item.isElem('svg') && item.closestElem('svg')) { + return; + } + + var nums = item.attr('viewBox').value.split(/[ ,]+/g); if ( - item.isElem(viewBoxElems) && - item.hasAttr('viewBox') && - item.hasAttr('width') && - item.hasAttr('height') + nums[0] === '0' && + nums[1] === '0' && + item.attr('width').value.replace(/px$/, '') === nums[2] && // could use parseFloat too + item.attr('height').value.replace(/px$/, '') === nums[3] ) { - - var nums = item.attr('viewBox').value.split(/[ ,]+/g); - - if ( - nums[0] === '0' && - nums[1] === '0' && - item.attr('width').value.replace(/px$/, '') === nums[2] && // could use parseFloat too - item.attr('height').value.replace(/px$/, '') === nums[3] - ) { - item.removeAttr('viewBox'); - } - + item.removeAttr('viewBox'); } - + } }; diff --git a/test/plugins/removeViewBox.05.svg b/test/plugins/removeViewBox.05.svg new file mode 100644 index 000000000..798f5a3ab --- /dev/null +++ b/test/plugins/removeViewBox.05.svg @@ -0,0 +1,29 @@ +ViewBox in nested should be preserved to not break scale + +=== + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + diff --git a/test/regression.js b/test/regression.js index 61ea0f29f..34e3de6cc 100644 --- a/test/regression.js +++ b/test/regression.js @@ -115,8 +115,8 @@ const runTests = async ({ svgFiles }) => { name === 'styling-css-01-b' || name === 'styling-css-03-b' || name === 'styling-css-04-f' || - // mismatched draft cases - name === 'struct-use-07-b' + // strange artifact breaks inconsistently breaks regression tests + name === 'filters-conv-05-f' ) { console.info(`${name} is skipped`); skipped += 1;