Skip to content

Commit

Permalink
Fix svg detection when it starts with a comment (#193)
Browse files Browse the repository at this point in the history
* Fix svg detection when it starts with a comment

* Add embedded SVG into HTML test sample

* Remove HTML comment tag from detector

Co-authored-by: Gabriel Vasile <gabriel.vasile@email.com>
  • Loading branch information
vitorduarte and gabriel-vasile committed Dec 14, 2021
1 parent 7e77ab6 commit db2464c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion internal/magic/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
[]byte("<BODY"),
[]byte("<BR"),
[]byte("<P"),
[]byte("<!--"),
)
// XML matches an Extensible Markup Language file.
XML = markup([]byte("<?XML"))
Expand Down
1 change: 1 addition & 0 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var files = map[string]string{
"heif.heif": "image/heif",
"html.html": "text/html; charset=utf-8",
"html.iso88591.html": "text/html; charset=iso-8859-1",
"html.svg.html": "text/html; charset=utf-8",
"html.usascii.html": "text/html; charset=us-ascii",
"html.utf8.html": "text/html; charset=utf-8",
"html.withbr.html": "text/html; charset=utf-8",
Expand Down
20 changes: 20 additions & 0 deletions testdata/html.svg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</style>
<link rel="stylesheet" href="css/animation.css">
<!--[if IE 7]><link rel="stylesheet" href="css/" + font.fontname + "-ie7.css"><![endif]-->
<script></script>
</head>
<body>
<div class="container footer"></div>
<!-- Generated by IcoMoon.io -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 112 90">
<path d="M68,87h-13l20-56h14l20,56h-13l-4-12h-20l-4,12zM75,65h14l-7-22l-7,22z
" fill="#2a376e"/>
<path d="M15,87h-13l20-56h14l19,56h-12l-4-12h-21l-3,12zM22,65h14l-7-22l-7,22z" fill="#bf2426"/>
<path d="M705,169c5,18,5,27-2,48l-58,172l-62-175c0,0,7-19,11-30c3,0,9,7,9,7c0,0-7-20-4-24l9-24l10,6c-2-6-5-19-5-19l9-28l10,5c0,0-7-19-5-22l24-63c20,47,36,98,54,147zM659,485c1,5,0,11-5,19c1,10,1,13-2,17c-3,3-6,4-10,4c1-3,1-7,0-8c-13-17-42-50-42-50h-15l-14,36l6,10c0,0,13,0,19,0c1,0,2,1,3,3v6c-1-1-3-2-4-3c-14,0-24,0-37,1l-4,2c-2-5,2-9,5-9c3,0,6,0,5-2c-1-3-2-4-5-7h-16c-16-46-33-92-47-139c6,0,14-3,14-3c0,0-16-6-20-15c-3-9-14-40-14-40c0,0,9-1,13-3c-5-4-18-8-20-14c-7-18-11-35-11-35c0,0,16-1,14-2c-9-4-21-16-21-16c0,0-11-31-11-31c1-1,16,0,16,0c-4-8-16-12-13-23c4-13,9-26,12-34l9,5c-1-5-4-23-4-23l12-35l9,7l-3-24l20-51l52,147l109,310zM475,476l-5-8l-6,8h-22l48-74l27,74h-14l-5-8l-5,8h-18z" fill="#2a376e" transform="scale(0.1)"/>
</svg>
</body>
</html>
1 change: 1 addition & 0 deletions testdata/svg.1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit db2464c

Please sign in to comment.