PLT-7563 Fixed template handling to support more values (#7404)

Этот коммит содержится в:
Harrison Healey
2017-09-14 02:29:30 -04:00
коммит произвёл Christopher Speller
родитель 1569702930
Коммит b4d662cce4

Просмотреть файл

@@ -7,6 +7,7 @@ import (
"bytes" "bytes"
"html/template" "html/template"
"net/http" "net/http"
"reflect"
l4g "github.com/alecthomas/log4go" l4g "github.com/alecthomas/log4go"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@@ -94,7 +95,7 @@ func (t *HTMLTemplate) addDefaultProps() {
} }
t.Html["EmailInfo"] = TranslateAsHtml(localT, "api.templates.email_info", t.Html["EmailInfo"] = TranslateAsHtml(localT, "api.templates.email_info",
map[string]interface{}{"SupportEmail": Cfg.SupportSettings.SupportEmail, "SiteName": Cfg.TeamSettings.SiteName}) map[string]interface{}{"SupportEmail": *Cfg.SupportSettings.SupportEmail, "SiteName": Cfg.TeamSettings.SiteName})
} }
func (t *HTMLTemplate) Render() string { func (t *HTMLTemplate) Render() string {
@@ -128,6 +129,8 @@ func escapeForHtml(arg interface{}) interface{} {
switch typedArg := arg.(type) { switch typedArg := arg.(type) {
case string: case string:
return template.HTMLEscapeString(typedArg) return template.HTMLEscapeString(typedArg)
case *string:
return template.HTMLEscapeString(*typedArg)
case map[string]interface{}: case map[string]interface{}:
safeArg := make(map[string]interface{}, len(typedArg)) safeArg := make(map[string]interface{}, len(typedArg))
for key, value := range typedArg { for key, value := range typedArg {
@@ -135,7 +138,7 @@ func escapeForHtml(arg interface{}) interface{} {
} }
return safeArg return safeArg
default: default:
l4g.Warn("Unable to escape value for HTML template %v", arg) l4g.Warn("Unable to escape value for HTML template %v of type %v", arg, reflect.ValueOf(arg).Type())
return "" return ""
} }
} }