Skip to content

Commit 3e94ac5

Browse files
authored
Improve QueryEscape helper function (#29768)
Make it return "template.URL" to follow Golang template's context auto-escaping.
1 parent 85c59d6 commit 3e94ac5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/templates/helper.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewFuncMap() template.FuncMap {
3838
"SafeHTML": SafeHTML,
3939
"HTMLFormat": HTMLFormat,
4040
"HTMLEscape": HTMLEscape,
41-
"QueryEscape": url.QueryEscape,
41+
"QueryEscape": QueryEscape,
4242
"JSEscape": JSEscapeSafe,
4343
"SanitizeHTML": SanitizeHTML,
4444
"URLJoin": util.URLJoin,
@@ -226,6 +226,10 @@ func JSEscapeSafe(s string) template.HTML {
226226
return template.HTML(template.JSEscapeString(s))
227227
}
228228

229+
func QueryEscape(s string) template.URL {
230+
return template.URL(url.QueryEscape(s))
231+
}
232+
229233
// DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls
230234
func DotEscape(raw string) string {
231235
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")

0 commit comments

Comments
 (0)