From 9b97e06ef69b7961f342c9ee8468c552c9b503a3 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 21 Feb 2021 14:50:55 +0300 Subject: [PATCH] Fix empty in cleanupIDs plugin --- plugins/cleanupIDs.js | 2 +- test/svgo/_index.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 71ffb5f9..bf541d13 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 b6c708a4..6eb0f558 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(''); + }); });