Skip to content

Commit

Permalink
Update Regex to handle DTD markup declarations (#9)
Browse files Browse the repository at this point in the history
* Update Regex to handle DTD markup declarations

Fixes #8

* Add test for DTD markup declaration
  • Loading branch information
kraftner authored and sindresorhus committed Nov 4, 2016
1 parent 3df0483 commit 4e69174
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 @@ -16,5 +16,5 @@ function isBinary(buf) {
}

module.exports = function (buf) {
return !isBinary(buf) && /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>[^]*<\/svg>\s*$/i.test(buf.toString().replace(htmlCommentRegex, ''));
return !isBinary(buf) && /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:<![^>]*>)*[^>]*>\s*)?<svg[^>]*>[^]*<\/svg>\s*$/i.test(buf.toString().replace(htmlCommentRegex, ''));
};
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test('valid SVGs', t => {
t.true(m('<svg width="100" height="100" viewBox="0 0 30 30" version="1.1"></svg>'));
t.true(m('<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>'));
t.true(m('<?xml version="1.0" standalone="no"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg></svg>'));
t.true(m('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">]><svg></svg>'));
t.true(m('<svg></svg> '));
t.true(m(' <svg></svg>'));
t.true(m('<svg>\n</svg>'));
Expand Down

0 comments on commit 4e69174

Please sign in to comment.