diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 848d4b4ad4..693ef90d65 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -54,7 +54,7 @@ func NewFuncMap() template.FuncMap { // html/template related functions "dict": dict, // it's lowercase because this name has been widely used. Our other functions should have uppercase names. "Eval": Eval, - "SafeHTML": SafeHTML, + "TrustHTML": TrustHTML, "HTMLFormat": HTMLFormat, "HTMLEscape": HTMLEscape, "QueryEscape": QueryEscape, @@ -240,8 +240,8 @@ func HTMLFormat(s string, rawArgs ...any) template.HTML { return template.HTML(fmt.Sprintf(s, args...)) } -// SafeHTML render raw as HTML -func SafeHTML(s any) template.HTML { +// TrustHTML render raw as HTML +func TrustHTML(s any) template.HTML { switch v := s.(type) { case string: return template.HTML(v) diff --git a/templates/admin/packages/list.tmpl b/templates/admin/packages/list.tmpl index ddb625fd8f..ce0903b576 100644 --- a/templates/admin/packages/list.tmpl +++ b/templates/admin/packages/list.tmpl @@ -89,7 +89,7 @@ {{ctx.Locale.Tr "packages.settings.delete"}}
- {{ctx.Locale.Tr "packages.settings.delete.notice" (``|SafeHTML) (``|SafeHTML)}} + {{ctx.Locale.Tr "packages.settings.delete.notice" (``|TrustHTML) (``|TrustHTML)}}
{{template "base/modal_actions_confirm" .}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 8f3f41cea9..465c51ddcf 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -103,7 +103,7 @@

{{ctx.Locale.Tr "repo.settings.delete_desc"}}

- {{ctx.Locale.Tr "repo.settings.delete_notices_2" (``|SafeHTML)}}
+ {{ctx.Locale.Tr "repo.settings.delete_notices_2" (``|TrustHTML)}}
{{ctx.Locale.Tr "repo.settings.delete_notices_fork_1"}}
{{template "base/modal_actions_confirm" .}} diff --git a/templates/admin/stacktrace.tmpl b/templates/admin/stacktrace.tmpl index 57c0c210cc..b89140483c 100644 --- a/templates/admin/stacktrace.tmpl +++ b/templates/admin/stacktrace.tmpl @@ -40,7 +40,7 @@ {{ctx.Locale.Tr "admin.monitor.process.cancel"}}
-

{{ctx.Locale.Tr "admin.monitor.process.cancel_notices" (``|SafeHTML)}}

+

{{ctx.Locale.Tr "admin.monitor.process.cancel_notices" (``|TrustHTML)}}

{{ctx.Locale.Tr "admin.monitor.process.cancel_desc"}}

{{template "base/modal_actions_confirm" .}} diff --git a/templates/org/member/members.tmpl b/templates/org/member/members.tmpl index 0cbc1b5eb1..24d7fd09e0 100644 --- a/templates/org/member/members.tmpl +++ b/templates/org/member/members.tmpl @@ -74,7 +74,7 @@ {{ctx.Locale.Tr "org.members.leave"}}
-

{{ctx.Locale.Tr "org.members.leave.detail" (``|SafeHTML)}}

+

{{ctx.Locale.Tr "org.members.leave.detail" (``|TrustHTML)}}

{{template "base/modal_actions_confirm" .}} @@ -83,7 +83,7 @@ {{ctx.Locale.Tr "org.members.remove"}}
-

{{ctx.Locale.Tr "org.members.remove.detail" (``|SafeHTML) (``|SafeHTML)}}

+

{{ctx.Locale.Tr "org.members.remove.detail" (``|TrustHTML) (``|TrustHTML)}}

{{template "base/modal_actions_confirm" .}} diff --git a/templates/org/team/members.tmpl b/templates/org/team/members.tmpl index 09b9ce3bf4..60667e963d 100644 --- a/templates/org/team/members.tmpl +++ b/templates/org/team/members.tmpl @@ -79,7 +79,7 @@ {{ctx.Locale.Tr "org.members.remove"}}
-

{{ctx.Locale.Tr "org.members.remove.detail" (``|SafeHTML) (``|SafeHTML)}}

+

{{ctx.Locale.Tr "org.members.remove.detail" (``|TrustHTML) (``|TrustHTML)}}

{{template "base/modal_actions_confirm" .}} diff --git a/templates/org/team/sidebar.tmpl b/templates/org/team/sidebar.tmpl index 2592a5a8d1..302827003f 100644 --- a/templates/org/team/sidebar.tmpl +++ b/templates/org/team/sidebar.tmpl @@ -84,7 +84,7 @@ {{ctx.Locale.Tr "org.teams.leave"}}
-

{{ctx.Locale.Tr "org.teams.leave.detail" (``|SafeHTML)}}

+

{{ctx.Locale.Tr "org.teams.leave.detail" (``|TrustHTML)}}

{{template "base/modal_actions_confirm" .}} diff --git a/templates/org/team/teams.tmpl b/templates/org/team/teams.tmpl index ef71c2652e..79749a1ee6 100644 --- a/templates/org/team/teams.tmpl +++ b/templates/org/team/teams.tmpl @@ -48,7 +48,7 @@ {{ctx.Locale.Tr "org.teams.leave"}}
-

{{ctx.Locale.Tr "org.teams.leave.detail" (``|SafeHTML)}}

+

{{ctx.Locale.Tr "org.teams.leave.detail" (``|TrustHTML)}}

{{template "base/modal_actions_confirm" .}} diff --git a/templates/repo/pulse.tmpl b/templates/repo/pulse.tmpl index 4e54bb881f..4077287434 100644 --- a/templates/repo/pulse.tmpl +++ b/templates/repo/pulse.tmpl @@ -35,7 +35,7 @@ {{end}} - {{ctx.Locale.TrPluralString .Activity.ActivePRCount "pulse.n_active_prs" (printf "%d" .Activity.ActivePRCount | SafeHTML)}} + {{ctx.Locale.TrPluralString .Activity.ActivePRCount "pulse.n_active_prs" (printf "%d" .Activity.ActivePRCount | TrustHTML)}} {{end}} {{if .Permission.CanRead $.UnitTypeIssues}} @@ -52,7 +52,7 @@ {{end}} - {{ctx.Locale.TrPluralString .Activity.ActiveIssueCount "pulse.n_active_issues" (printf "%d" .Activity.ActiveIssueCount | SafeHTML)}} + {{ctx.Locale.TrPluralString .Activity.ActiveIssueCount "pulse.n_active_issues" (printf "%d" .Activity.ActiveIssueCount | TrustHTML)}} {{end}} diff --git a/templates/repo/settings/lfs_file.tmpl b/templates/repo/settings/lfs_file.tmpl index 00bbae616a..ebbcc9b1f8 100644 --- a/templates/repo/settings/lfs_file.tmpl +++ b/templates/repo/settings/lfs_file.tmpl @@ -15,9 +15,9 @@ {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}}
{{if .IsMarkup}} - {{if .FileContent}}{{.FileContent | SafeHTML}}{{end}} + {{if .FileContent}}{{.FileContent | TrustHTML}}{{end}} {{else if .IsPlainText}} -
{{if .FileContent}}{{.FileContent | SafeHTML}}{{end}}
+
{{if .FileContent}}{{.FileContent | TrustHTML}}{{end}}
{{else if not .IsTextFile}}
{{if .IsImageFile}} diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index b79b14d059..96ecfdb50c 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -3,14 +3,14 @@
{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo)}} - {{svg "octicon-history"}} {{ctx.Locale.TrN .CommitsCount "repo.n_commit_one" "repo.n_commit_few" (printf "%s" (ctx.Locale.PrettyNumber .CommitsCount) | SafeHTML)}} + {{svg "octicon-history"}} {{ctx.Locale.TrN .CommitsCount "repo.n_commit_one" "repo.n_commit_few" (printf "%s" (ctx.Locale.PrettyNumber .CommitsCount) | TrustHTML)}} - {{svg "octicon-git-branch"}} {{ctx.Locale.TrN .BranchesCount "repo.n_branch_one" "repo.n_branch_few" (printf "%s" (ctx.Locale.PrettyNumber .BranchesCount) | SafeHTML)}} + {{svg "octicon-git-branch"}} {{ctx.Locale.TrN .BranchesCount "repo.n_branch_one" "repo.n_branch_few" (printf "%s" (ctx.Locale.PrettyNumber .BranchesCount) | TrustHTML)}} {{if $.Permission.CanRead $.UnitTypeCode}} - {{svg "octicon-tag"}} {{ctx.Locale.TrN .NumTags "repo.n_tag_one" "repo.n_tag_few" (printf "%s" (ctx.Locale.PrettyNumber .NumTags) | SafeHTML)}} + {{svg "octicon-tag"}} {{ctx.Locale.TrN .NumTags "repo.n_tag_one" "repo.n_tag_few" (printf "%s" (ctx.Locale.PrettyNumber .NumTags) | TrustHTML)}} {{end}} diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl index 1a0da970a1..7d41452b05 100644 --- a/templates/repo/wiki/view.tmpl +++ b/templates/repo/wiki/view.tmpl @@ -76,13 +76,13 @@
{{if .sidebarTocContent}} {{end}}
{{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}} - {{.content | SafeHTML}} + {{.content | TrustHTML}}
{{if .sidebarPresent}} @@ -91,7 +91,7 @@ {{if and .CanWriteWiki (not .Repository.IsMirror)}} {{svg "octicon-pencil"}} {{end}} - {{.sidebarContent | SafeHTML}} + {{.sidebarContent | TrustHTML}}
{{end}} @@ -103,7 +103,7 @@ {{if and .CanWriteWiki (not .Repository.IsMirror)}} {{svg "octicon-pencil"}} {{end}} - {{.footerContent | SafeHTML}} + {{.footerContent | TrustHTML}}
{{end}}
diff --git a/templates/user/settings/organization.tmpl b/templates/user/settings/organization.tmpl index e3a8ec1471..13749806c6 100644 --- a/templates/user/settings/organization.tmpl +++ b/templates/user/settings/organization.tmpl @@ -46,7 +46,7 @@ {{ctx.Locale.Tr "org.members.leave"}}
-

{{ctx.Locale.Tr "org.members.leave.detail" (``|SafeHTML)}}

+

{{ctx.Locale.Tr "org.members.leave.detail" (``|TrustHTML)}}

{{template "base/modal_actions_confirm" .}} diff --git a/templates/webhook/new/matrix.tmpl b/templates/webhook/new/matrix.tmpl index e8ba210187..b8d00633ee 100644 --- a/templates/webhook/new/matrix.tmpl +++ b/templates/webhook/new/matrix.tmpl @@ -13,7 +13,7 @@
- {{ctx.Locale.Tr "repo.settings.matrix.room_id_helper" ("!opaque_id:example.org"|SafeHTML)}} + {{ctx.Locale.Tr "repo.settings.matrix.room_id_helper" ("!opaque_id:example.org"|TrustHTML)}}
diff --git a/templates/webhook/shared-settings.tmpl b/templates/webhook/shared-settings.tmpl index 47bce87e9e..95d91f5c30 100644 --- a/templates/webhook/shared-settings.tmpl +++ b/templates/webhook/shared-settings.tmpl @@ -192,7 +192,7 @@
- {{ctx.Locale.Tr "repo.settings.authorization_header_desc" ("Bearer token123456, Basic YWxhZGRpbjpvcGVuc2VzYW1l" | SafeHTML)}} + {{ctx.Locale.Tr "repo.settings.authorization_header_desc" ("Bearer token123456, Basic YWxhZGRpbjpvcGVuc2VzYW1l" | TrustHTML)}}
{{end}}