Skip to content

Commit

Permalink
Fix empty <svg /> in cleanupIDs plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Feb 21, 2021
1 parent 727646e commit 9b97e06
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/cleanupIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
4 changes: 4 additions & 0 deletions test/svgo/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<svg />', { input: 'file', path: 'input.svg' });
expect(result.data).to.equal('<svg/>');
});
});

0 comments on commit 9b97e06

Please sign in to comment.