diff options
author | clsr <clsr@clsr.net> | 2016-12-16 15:58:43 +0100 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2016-12-16 15:58:43 +0100 |
commit | 40c71b5b843a28718339579dbef22bf0ccdab6ab (patch) | |
tree | f6e682fdf81edec36479e2f44ededaeccf808895 | |
parent | c18de344e98be8c1d6d91516cf1ae5127e8e274a (diff) | |
download | gomf-40c71b5b843a28718339579dbef22bf0ccdab6ab.tar.gz gomf-40c71b5b843a28718339579dbef22bf0ccdab6ab.zip |
Fix file extension detection when upload name has nonev0.5.2
-rw-r--r-- | storage/storage.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/storage/storage.go b/storage/storage.go index 3e2b816..b8b20e1 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -190,7 +190,7 @@ func (s *Storage) getMimeExt(fpath string, name string) (mimetype, ext string, e if err != nil { return } - if ext != "" && find(exts, ext) == "" { + if !contains(exts, ext) { ext = "" if len(exts) > 0 { ext = exts[0] @@ -202,7 +202,7 @@ func (s *Storage) getMimeExt(fpath string, name string) (mimetype, ext string, e err = ErrForbidden{mimetype} } else if ok && !s.Whitelist { // blacklist: reject if filtered // only block application/octet-stream if explicitly requested - if mimetype != "application/octet-stream" || find(s.FilterMime, mimetype) != "" { + if mimetype != "application/octet-stream" || contains(s.FilterMime, mimetype) { err = ErrForbidden{filtered} } } @@ -211,12 +211,12 @@ func (s *Storage) getMimeExt(fpath string, name string) (mimetype, ext string, e } func (s *Storage) findFilter(exts []string, mimetype string) (match string, ok bool) { - if m := find(s.FilterMime, mimetype); m == mimetype { - return m, true + if contains(s.FilterMime, mimetype) { + return mimetype, true } for _, ext := range exts { - if e := find(s.FilterExt, ext); e == ext { - return e, true + if contains(s.FilterExt, ext) { + return ext, true } } return "", false @@ -270,11 +270,11 @@ func (s *Storage) storeFile(file *os.File, hash, ext string) (id string, err err return } -func find(ss []string, search string) string { +func contains(ss []string, search string) bool { for _, s := range ss { if s == search { - return s + return true } } - return "" + return false } |