|
|
@ -38,7 +38,7 @@ func NewFuncMap() template.FuncMap { |
|
|
|
"Iif": iif, |
|
|
|
"Iif": iif, |
|
|
|
"Eval": evalTokens, |
|
|
|
"Eval": evalTokens, |
|
|
|
"SafeHTML": safeHTML, |
|
|
|
"SafeHTML": safeHTML, |
|
|
|
"HTMLFormat": htmlutil.HTMLFormat, |
|
|
|
"HTMLFormat": htmlFormat, |
|
|
|
"HTMLEscape": htmlEscape, |
|
|
|
"HTMLEscape": htmlEscape, |
|
|
|
"QueryEscape": queryEscape, |
|
|
|
"QueryEscape": queryEscape, |
|
|
|
"QueryBuild": QueryBuild, |
|
|
|
"QueryBuild": QueryBuild, |
|
|
@ -207,6 +207,20 @@ func htmlEscape(s any) template.HTML { |
|
|
|
panic(fmt.Sprintf("unexpected type %T", s)) |
|
|
|
panic(fmt.Sprintf("unexpected type %T", s)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func htmlFormat(s any, args ...any) template.HTML { |
|
|
|
|
|
|
|
if len(args) == 0 { |
|
|
|
|
|
|
|
// to prevent developers from calling "HTMLFormat $userInput" by mistake which will lead to XSS
|
|
|
|
|
|
|
|
panic("missing arguments for HTMLFormat") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch v := s.(type) { |
|
|
|
|
|
|
|
case string: |
|
|
|
|
|
|
|
return htmlutil.HTMLFormat(template.HTML(v), args...) |
|
|
|
|
|
|
|
case template.HTML: |
|
|
|
|
|
|
|
return htmlutil.HTMLFormat(v, args...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
panic(fmt.Sprintf("unexpected type %T", s)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func jsEscapeSafe(s string) template.HTML { |
|
|
|
func jsEscapeSafe(s string) template.HTML { |
|
|
|
return template.HTML(template.JSEscapeString(s)) |
|
|
|
return template.HTML(template.JSEscapeString(s)) |
|
|
|
} |
|
|
|
} |
|
|
|