mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
fix(type): svg type checking
This commit is contained in:
parent
ac42bba851
commit
de76daee9c
1 changed files with 3 additions and 3 deletions
6
type.go
6
type.go
|
|
@ -30,8 +30,8 @@ const (
|
|||
type ImageType int
|
||||
|
||||
var (
|
||||
htmlCommentRegex = regexp.MustCompile("<!--([\\s\\S]*?)-->")
|
||||
svgRegex = regexp.MustCompile(`^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>[^*]*<\/svg>\s*$`)
|
||||
htmlCommentRegex = regexp.MustCompile("(?i)<!--([\\s\\S]*?)-->")
|
||||
svgRegex = regexp.MustCompile(`(?i)^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>[^*]*<\/svg>\s*$`)
|
||||
)
|
||||
|
||||
// ImageTypes stores as pairs of image types supported and its alias names.
|
||||
|
|
@ -75,7 +75,7 @@ func isBinary(buf []byte) bool {
|
|||
|
||||
// IsSVGImage returns true if the given buffer is a valid SVG image.
|
||||
func IsSVGImage(buf []byte) bool {
|
||||
return !isBinary(buf) && svgRegex.Match(htmlCommentRegex.ReplaceAll(buf, []byte{0}))
|
||||
return !isBinary(buf) && svgRegex.Match(htmlCommentRegex.ReplaceAll(buf, []byte{}))
|
||||
}
|
||||
|
||||
// DetermineImageType determines the image type format (jpeg, png, webp or tiff)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue