Skip to content

Commit 10c7996

Browse files
authored
Remove RenderEmojiPlain from template helper (go-gitea#29375)
RenderEmojiPlain(emoji.ReplaceAliases) should be called explicitly for some contents, but not for everything. Actually in modern days, in most cases it doesn't need such "ReplaceAliases". So only keep it for issue/PR titles. If anyone really needs to do ReplaceAliases for some contents, I will propose a following fix.
1 parent ff9dc51 commit 10c7996

File tree

6 files changed

+10
-20
lines changed

6 files changed

+10
-20
lines changed

modules/templates/helper.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
user_model "code.gitea.io/gitea/models/user"
1616
"code.gitea.io/gitea/modules/base"
17-
"code.gitea.io/gitea/modules/emoji"
1817
"code.gitea.io/gitea/modules/markup"
1918
"code.gitea.io/gitea/modules/setting"
2019
"code.gitea.io/gitea/modules/svg"
@@ -159,7 +158,6 @@ func NewFuncMap() template.FuncMap {
159158
"RenderCodeBlock": RenderCodeBlock,
160159
"RenderIssueTitle": RenderIssueTitle,
161160
"RenderEmoji": RenderEmoji,
162-
"RenderEmojiPlain": RenderEmojiPlain,
163161
"ReactionToEmoji": ReactionToEmoji,
164162

165163
"RenderMarkdownToHtml": RenderMarkdownToHtml,
@@ -215,16 +213,6 @@ func JSEscapeSafe(s string) template.HTML {
215213
return template.HTML(template.JSEscapeString(s))
216214
}
217215

218-
func RenderEmojiPlain(s any) any {
219-
switch v := s.(type) {
220-
case string:
221-
return emoji.ReplaceAliases(v)
222-
case template.HTML:
223-
return template.HTML(emoji.ReplaceAliases(string(v)))
224-
}
225-
panic(fmt.Sprintf("unexpected type %T", s))
226-
}
227-
228216
// DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls
229217
func DotEscape(raw string) string {
230218
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")

routers/web/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"code.gitea.io/gitea/modules/base"
3333
"code.gitea.io/gitea/modules/container"
3434
"code.gitea.io/gitea/modules/context"
35+
"code.gitea.io/gitea/modules/emoji"
3536
"code.gitea.io/gitea/modules/git"
3637
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
3738
issue_template "code.gitea.io/gitea/modules/issue/template"
@@ -1435,7 +1436,7 @@ func ViewIssue(ctx *context.Context) {
14351436
return
14361437
}
14371438

1438-
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
1439+
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
14391440

14401441
iw := new(issues_model.IssueWatch)
14411442
if ctx.Doer != nil {

routers/web/repo/pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
user_model "code.gitea.io/gitea/models/user"
2929
"code.gitea.io/gitea/modules/base"
3030
"code.gitea.io/gitea/modules/context"
31+
"code.gitea.io/gitea/modules/emoji"
3132
"code.gitea.io/gitea/modules/git"
3233
"code.gitea.io/gitea/modules/gitrepo"
3334
issue_template "code.gitea.io/gitea/modules/issue/template"
@@ -335,7 +336,7 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) {
335336
ctx.ServerError("LoadRepo", err)
336337
return nil, false
337338
}
338-
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
339+
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
339340
ctx.Data["Issue"] = issue
340341

341342
if !issue.IsPull {

templates/base/head.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="{{ctx.Locale.Lang}}" data-theme="{{ThemeName .SignedUser}}">
33
<head>
44
<meta name="viewport" content="width=device-width, initial-scale=1">
5-
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}}{{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
5+
<title>{{if .Title}}{{.Title}} - {{end}}{{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
66
{{if .ManifestData}}<link rel="manifest" href="data:{{.ManifestData}}">{{end}}
77
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}">
88
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}">

templates/repo/issue/choose.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<div class="ui attached segment">
1212
<div class="ui two column grid">
1313
<div class="column left aligned">
14-
<strong>{{.Name | RenderEmojiPlain}}</strong>
15-
<br>{{.About | RenderEmojiPlain}}
14+
<strong>{{.Name}}</strong>
15+
<br>{{.About}}
1616
</div>
1717
<div class="column right aligned">
1818
<a href="{{$.RepoLink}}/issues/new?template={{.FileName}}{{if $.milestone}}&milestone={{$.milestone}}{{end}}{{if $.project}}&project={{$.project}}{{end}}" class="ui primary button">{{ctx.Locale.Tr "repo.issues.choose.get_started"}}</a>
@@ -24,8 +24,8 @@
2424
<div class="ui attached segment">
2525
<div class="ui two column grid">
2626
<div class="column left aligned">
27-
<strong>{{.Name | RenderEmojiPlain}}</strong>
28-
<br>{{.About | RenderEmojiPlain}}
27+
<strong>{{.Name}}</strong>
28+
<br>{{.About}}
2929
</div>
3030
<div class="column right aligned">
3131
<a href="{{.URL}}" class="ui primary button">{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.issues.choose.open_external_link"}}</a>

templates/repo/settings/lfs_file_find.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</td>
1515
<td class="message">
1616
<span class="truncate">
17-
<a href="{{$.RepoLink}}/commit/{{.SHA}}" title="{{.Summary | RenderEmojiPlain}}">
17+
<a href="{{$.RepoLink}}/commit/{{.SHA}}" title="{{.Summary}}">
1818
{{.Summary | RenderEmoji $.Context}}
1919
</a>
2020
</span>

0 commit comments

Comments
 (0)