diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 71ffb5f93..bf541d132 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -65,7 +65,7 @@ exports.fn = function(data, params) { } // Don't remove IDs if the whole SVG consists only of defs. - if (item.isElem('svg')) { + if (item.isElem('svg') && item.content) { var hasDefsOnly = true; for (var j = 0; j < item.content.length; j++) { diff --git a/test/svgo/_index.js b/test/svgo/_index.js index b6c708a44..6eb0f5589 100644 --- a/test/svgo/_index.js +++ b/test/svgo/_index.js @@ -57,4 +57,8 @@ describe('svgo', () => { expect(result.error).to.match(/Error in parsing SVG/); expect(result.path).to.equal('input.svg'); }); + it('should handle empty svg tag', async () => { + const result = optimize('', { input: 'file', path: 'input.svg' }); + expect(result.data).to.equal(''); + }); });