Skip to content

Commit

Permalink
Allow self-closing SVG tag (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
tprobinson authored and sindresorhus committed May 30, 2019
1 parent e7a602f commit 23d6d27
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isBinary = buffer => {
return false;
};

const regex = /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>]*>\s*)*\]?)*[^>]*>\s*)?<svg[^>]*>[^]*<\/svg>\s*$/i;
const regex = /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>]*>\s*)*\]?)*[^>]*>\s*)?(?:<svg[^>]*>[^]*<\/svg>|<svg[^/>]*\/\s*>)\s*$/i;

const isSvg = input => Boolean(input) && !isBinary(input) && regex.test(input.toString().replace(htmlCommentRegex, ''));

Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('valid SVGs', t => {
t.true(isSvg(' <svg></svg>'));
t.true(isSvg('<svg>\n</svg>'));
t.true(isSvg('<!--unicorn--><svg>\n</svg><!--cake-->'));
t.true(isSvg('<svg/>'));
t.true(isSvg(`
<!-- Generator: Some Graphic Design Software -->
<svg version="1.1">
Expand Down

0 comments on commit 23d6d27

Please sign in to comment.