From 25b23c4bc991644c7db47b484dca3bb2d2694e62 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 11 Aug 2016 20:16:36 -0300 Subject: Do not show non-image attachment in a tag. Fixes #3215 (#3311) --- modules/template/template.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'modules/template') 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/") + }, }} } -- cgit v1.2.3