Do not show non-image attachment in a <img> tag. Fixes #3215 (#3311)

This commit is contained in:
Andrey Nering 2016-08-11 20:16:36 -03:00 committed by 无闻
parent 7eafe3213f
commit 25b23c4bc9
4 changed files with 29 additions and 2 deletions

View file

@ -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/")
},
}}
}