Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Jul 12, 2024
1 parent 8a24251 commit 865d3d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
23 changes: 17 additions & 6 deletions upload/filetype_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@ import (
"regexp"
"strings"

"github.com/admpub/safesvg"
"github.com/h2non/filetype"
"github.com/h2non/filetype/matchers"
"github.com/h2non/filetype/types"
svg "github.com/h2non/go-is-svg"
"github.com/hamochi/safesvg"
)

var ReadHeadSizeBytes = 261
var SVGMaxSizeBytes int64 = 5 * 1024 * 1024
var ErrIncorrectFileFormat = errors.New(`file format is incorrect`)
var defaultSafeSVGValidator = safesvg.NewValidator()
var svgHeadRegex = regexp.MustCompile(`(?i)^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>`)
var (
ReadHeadSizeBytes = 261
SVGMaxSizeBytes int64 = 5 * 1024 * 1024
ErrIncorrectFileFormat = errors.New(`file format is incorrect`)
defaultSafeSVGValidator = safesvg.NewValidator()
svgHeadRegex = regexp.MustCompile(`(?i)^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>`)
)

func init() {
defaultSafeSVGValidator.WhitelistElements(`style`)
defaultSafeSVGValidator.WhitelistAttributes(`http://www.w3.org/1999/xlink:href`, `data-name`)
}

func SafeSVGValidator() safesvg.Validator {
return defaultSafeSVGValidator
}

func ReadHeadBytes(r io.Reader, readSizes ...int) ([]byte, error) {
readSize := ReadHeadSizeBytes
Expand Down
Loading

0 comments on commit 865d3d1

Please sign in to comment.