diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-03-13 14:32:30 +0100 |
---|---|---|
committer | Earl Warren <contact@earl-warren.org> | 2024-03-20 08:46:29 +0100 |
commit | 5bb08e2bd7914755f3cca8b808ecadb9be11f1b1 (patch) | |
tree | f0b80807cdde3f16e9ff1a72700b1260641eba4e /modules | |
parent | Use relative links for commits, mentions, and issues in markdown (#29427) (fo... (diff) | |
download | forgejo-5bb08e2bd7914755f3cca8b808ecadb9be11f1b1.tar.xz forgejo-5bb08e2bd7914755f3cca8b808ecadb9be11f1b1.zip |
Improve QueryEscape helper function (#29768)
Make it return "template.URL" to follow Golang template's context
auto-escaping.
(cherry picked from commit 3e94ac5c7c6751919453fdb66ba3472e2793759e)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/templates/helper.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 7ef051cc0b..18a2993fb8 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -38,7 +38,7 @@ func NewFuncMap() template.FuncMap { "SafeHTML": SafeHTML, "HTMLFormat": HTMLFormat, "HTMLEscape": HTMLEscape, - "QueryEscape": url.QueryEscape, + "QueryEscape": QueryEscape, "JSEscape": JSEscapeSafe, "SanitizeHTML": SanitizeHTML, "URLJoin": util.URLJoin, @@ -229,6 +229,10 @@ func JSEscapeSafe(s string) template.HTML { return template.HTML(template.JSEscapeString(s)) } +func QueryEscape(s string) template.URL { + return template.URL(url.QueryEscape(s)) +} + // DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls func DotEscape(raw string) string { return strings.ReplaceAll(raw, ".", "\u200d.\u200d") |