diff --git a/lib/path.js b/lib/path.js index b0e7f29..6d2d33d 100644 --- a/lib/path.js +++ b/lib/path.js @@ -305,6 +305,9 @@ export const stringifyPathData = ({ precision, disableSpaceAfterFlags, }) => { + if (pathData.length === 0) { + return ''; + } if (pathData.length === 1) { const { command, args } = pathData[0]; return ( diff --git a/lib/path.test.js b/test/lib/path.test.js similarity index 93% rename from lib/path.test.js rename to test/lib/path.test.js index 0197e1d..ef1685d 100644 --- a/lib/path.test.js +++ b/test/lib/path.test.js @@ -1,8 +1,4 @@ -import { parsePathData, stringifyPathData } from './path.js'; - -/** - * @typedef {import('../lib/types.js').PathDataItem} PathDataItem - */ +import { parsePathData, stringifyPathData } from '../../lib/path.js'; describe('parse path data', () => { it('should allow spaces between commands', () => { @@ -155,7 +151,7 @@ describe('stringify path data', () => { }); it('should configure precision', () => { /** - * @type {PathDataItem[]} + * @type {import('../../lib/types.js').PathDataItem[]} */ const pathData = [ { command: 'M', args: [0, -1.9876] }, @@ -178,7 +174,7 @@ describe('stringify path data', () => { }); it('allows to avoid spaces after arc flags', () => { /** - * @type {PathDataItem[]} + * @type {import('../../lib/types.js').PathDataItem[]} */ const pathData = [ { command: 'M', args: [0, 0] }, @@ -199,4 +195,14 @@ describe('stringify path data', () => { }), ).toBe('M0 0A50 50 10 10.2 20a50 50 10 10.2 20 50 50 10 10.2 20'); }); + + it('handles empty paths', () => { + /** @type {import('../../lib/types.js').PathDataItem[]} */ + const pathData = []; + expect( + stringifyPathData({ + pathData, + }), + ).toBe(''); + }); }); diff --git a/test/plugins/combinePaths.28.svg.txt b/test/plugins/combinePaths.28.svg.txt new file mode 100644 index 0000000..7564436 --- /dev/null +++ b/test/plugins/combinePaths.28.svg.txt @@ -0,0 +1,21 @@ +Make sure empty paths don't cause trouble. + +=== + + + + + + + + + + +@@@ + + + + + + + diff --git a/test/plugins/minifyPathData.48.svg.txt b/test/plugins/minifyPathData.48.svg.txt new file mode 100644 index 0000000..1dfa0a6 --- /dev/null +++ b/test/plugins/minifyPathData.48.svg.txt @@ -0,0 +1,14 @@ +Make sure empty paths don't cause trouble. + +=== + + + + + +@@@ + + + + +