1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Rename Str2html to SanitizeHTML and clarify its behavior (#29516)

Str2html was abused a lot. So use a proper name for it: SanitizeHTML

And add some tests to show its behavior.
This commit is contained in:
wxiaoguang
2024-03-01 18:16:19 +08:00
committed by GitHub
parent cb52b17f92
commit fb42972c05
14 changed files with 48 additions and 43 deletions

View File

@@ -1,20 +1,20 @@
{{if .Flash.ErrorMsg}}
<div class="ui negative message flash-message flash-error">
<p>{{.Flash.ErrorMsg | Str2html}}</p>
<p>{{.Flash.ErrorMsg | SanitizeHTML}}</p>
</div>
{{end}}
{{if .Flash.SuccessMsg}}
<div class="ui positive message flash-message flash-success">
<p>{{.Flash.SuccessMsg | Str2html}}</p>
<p>{{.Flash.SuccessMsg | SanitizeHTML}}</p>
</div>
{{end}}
{{if .Flash.InfoMsg}}
<div class="ui info message flash-message flash-info">
<p>{{.Flash.InfoMsg | Str2html}}</p>
<p>{{.Flash.InfoMsg | SanitizeHTML}}</p>
</div>
{{end}}
{{if .Flash.WarningMsg}}
<div class="ui warning message flash-message flash-warning">
<p>{{.Flash.WarningMsg | Str2html}}</p>
<p>{{.Flash.WarningMsg | SanitizeHTML}}</p>
</div>
{{end}}

View File

@@ -2,6 +2,6 @@
<details>
<summary>{{.Summary}}</summary>
<code>
{{.Details | Str2html}}
{{.Details | SanitizeHTML}}
</code>
</details>

View File

@@ -58,7 +58,7 @@
{{.locale.Tr "mail.issue.action.new" .Doer.Name .Issue.Index}}
{{end}}
{{else}}
{{.Body | Str2html}}
{{.Body | SanitizeHTML}}
{{end -}}
{{- range .ReviewComments}}
<hr>

View File

@@ -276,7 +276,7 @@
<span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When ctx.Locale}}</span>
</div>
<div class="ui bottom attached info segment git-notes">
<pre class="commit-body">{{.NoteRendered | Str2html}}</pre>
<pre class="commit-body">{{.NoteRendered | SanitizeHTML}}</pre>
</div>
{{end}}
{{template "repo/diff/box" .}}

View File

@@ -162,7 +162,7 @@
</span>
<div class="detail">
{{svg "octicon-git-commit"}}
<span class="text grey muted-links">{{.Content | Str2html}}</span>
<span class="text grey muted-links">{{.Content | SanitizeHTML}}</span>
</div>
</div>
{{else if eq .Type 7}}

View File

@@ -10,7 +10,7 @@
<div class="ui attached segment">
<div class="ui list">
<div class="item">
{{.Description | Str2html}}
{{.Description | SanitizeHTML}}
</div>
{{range .Webhooks}}
<div class="item truncated-item-container">

View File

@@ -1,5 +1,5 @@
{{/* This page should only depend the minimal template functions/variables, to avoid triggering new panics.
* base template functions: AppName, AssetUrlPrefix, AssetVersion, AppSubUrl, ThemeName, Str2html
* base template functions: AppName, AssetUrlPrefix, AssetVersion, AppSubUrl, ThemeName, SanitizeHTML
* ctx.Locale
* .Flash
* .ErrorMsg