From 5481fc24779d1369ff015bc600cb247e16f5619d Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Fri, 14 Jun 2024 12:48:56 +0100 Subject: [PATCH] fix: don't insert 0 at start or end of attribute if whitespace (#2036) --- docs/03-plugins/cleanupNumericValues.mdx | 2 +- plugins/cleanupNumericValues.js | 3 ++- test/plugins/cleanupNumericValues.03.svg.txt | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/plugins/cleanupNumericValues.03.svg.txt diff --git a/docs/03-plugins/cleanupNumericValues.mdx b/docs/03-plugins/cleanupNumericValues.mdx index a46c5ed9..0da3dca1 100644 --- a/docs/03-plugins/cleanupNumericValues.mdx +++ b/docs/03-plugins/cleanupNumericValues.mdx @@ -18,4 +18,4 @@ svgo: default: true --- -Rounds numeric values, and removes the unit when it's `px` as this is the default. +Rounds numeric values, removes the unit when it's `px` as this is the default, and removes redundant spaces around and between numbers. diff --git a/plugins/cleanupNumericValues.js b/plugins/cleanupNumericValues.js index 03714097..357e887e 100644 --- a/plugins/cleanupNumericValues.js +++ b/plugins/cleanupNumericValues.js @@ -39,6 +39,7 @@ export const fn = (_root, params) => { if (node.attributes.viewBox != null) { const nums = node.attributes.viewBox.split(/\s,?\s*|,\s*/g); node.attributes.viewBox = nums + .filter((value) => value.length != 0) .map((value) => { const num = Number(value); return Number.isNaN(num) @@ -54,7 +55,7 @@ export const fn = (_root, params) => { continue; } - const match = value.match(regNumericValues); + const match = regNumericValues.exec(value); // if attribute value matches regNumericValues if (match) { diff --git a/test/plugins/cleanupNumericValues.03.svg.txt b/test/plugins/cleanupNumericValues.03.svg.txt new file mode 100644 index 00000000..976d8046 --- /dev/null +++ b/test/plugins/cleanupNumericValues.03.svg.txt @@ -0,0 +1,5 @@ + + +@@@ + +