summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2016-08-11 20:16:36 -0300
committer无闻 <u@gogs.io>2016-08-11 16:16:36 -0700
commit25b23c4bc991644c7db47b484dca3bb2d2694e62 (patch)
treee73bc7c63cf91870df49cd2cb3c91c9e7ef152ea /modules
parent7eafe3213f456bb4fcbaeea5562ab60c4ef6cf87 (diff)
downloadgitea-25b23c4bc991644c7db47b484dca3bb2d2694e62.tar.gz
gitea-25b23c4bc991644c7db47b484dca3bb2d2694e62.zip
Do not show non-image attachment in a <img> tag. Fixes #3215 (#3311)
Diffstat (limited to 'modules')
-rw-r--r--modules/template/template.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/modules/template/template.go b/modules/template/template.go
index 76ab66bcb4..6e9b15b9be 100644
--- a/modules/template/template.go
+++ b/modules/template/template.go
@@ -9,6 +9,8 @@ import (
"encoding/json"
"fmt"
"html/template"
+ "mime"
+ "path/filepath"
"runtime"
"strings"
"time"
@@ -103,6 +105,10 @@ func NewFuncMap() []template.FuncMap {
"ThemeColorMetaTag": func() string {
return setting.UI.ThemeColorMetaTag
},
+ "FilenameIsImage": func(filename string) bool {
+ mimeType := mime.TypeByExtension(filepath.Ext(filename))
+ return strings.HasPrefix(mimeType, "image/")
+ },
}}
}