Skip to content

Commit 9b97e06

Browse files
committed
Fix empty <svg /> in cleanupIDs plugin
1 parent 727646e commit 9b97e06

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

plugins/cleanupIDs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ exports.fn = function(data, params) {
6565
}
6666

6767
// Don't remove IDs if the whole SVG consists only of defs.
68-
if (item.isElem('svg')) {
68+
if (item.isElem('svg') && item.content) {
6969
var hasDefsOnly = true;
7070

7171
for (var j = 0; j < item.content.length; j++) {

test/svgo/_index.js

+4
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ describe('svgo', () => {
5757
expect(result.error).to.match(/Error in parsing SVG/);
5858
expect(result.path).to.equal('input.svg');
5959
});
60+
it('should handle empty svg tag', async () => {
61+
const result = optimize('<svg />', { input: 'file', path: 'input.svg' });
62+
expect(result.data).to.equal('<svg/>');
63+
});
6064
});

0 commit comments

Comments
 (0)