Allow mime types to match based off of prefix

The old behavior prevented simple file types like "text/plain" from
being uploaded since browsers upload them with the charset as well (e.g.
`text/plain charset=utf-8`) without specifying all possible charsets.

Additionally, this allows for blanket includes like "text/" or "image/"
by class type.

There should be minimal risk introduced here as mime types are generally
hierarchical, but an alternative approach would be the equivalent of

```
if allowed.endsWith("*") && strings.HasPrefix(fileType,
    allowed.substr(0, allowed.length - 1) { ....
```
This commit is contained in:
Mahmoud Al-Qudsi 2018-03-02 18:13:57 -06:00
parent be825aaa88
commit 278d85206d

View File

@ -48,7 +48,7 @@ func UploadAttachment(ctx *context.Context) {
allowed := false
for _, t := range allowedTypes {
t := strings.Trim(t, " ")
if t == "*/*" || t == fileType {
if t == "*/*" || strings.HasPrefix(fileType, t) {
allowed = true
break
}