Skip to content

Commit 278d852

Browse files
committed
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) { .... ```
1 parent be825aa commit 278d852

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

routers/repo/attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func UploadAttachment(ctx *context.Context) {
4848
allowed := false
4949
for _, t := range allowedTypes {
5050
t := strings.Trim(t, " ")
51-
if t == "*/*" || t == fileType {
51+
if t == "*/*" || strings.HasPrefix(fileType, t) {
5252
allowed = true
5353
break
5454
}

0 commit comments

Comments
 (0)