Skip to content

Commit 9ef34fa

Browse files
committed
fix
1 parent d32648b commit 9ef34fa

File tree

177 files changed

+839
-839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+839
-839
lines changed

Diff for: modules/templates/helper.go

+34-34
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ func NewFuncMap() template.FuncMap {
3636
// -----------------------------------------------------------------
3737
// html/template related functions
3838
"dict": dict, // it's lowercase because this name has been widely used. Our other functions should have uppercase names.
39-
"Iif": Iif,
40-
"Eval": Eval,
41-
"SafeHTML": SafeHTML,
39+
"Iif": iif,
40+
"Eval": evalTokens,
41+
"SafeHTML": safeHTML,
4242
"HTMLFormat": HTMLFormat,
43-
"HTMLEscape": HTMLEscape,
44-
"QueryEscape": QueryEscape,
45-
"JSEscape": JSEscapeSafe,
43+
"HTMLEscape": htmlEscape,
44+
"QueryEscape": queryEscape,
45+
"JSEscape": jsEscapeSafe,
4646
"SanitizeHTML": SanitizeHTML,
4747
"URLJoin": util.URLJoin,
48-
"DotEscape": DotEscape,
48+
"DotEscape": dotEscape,
4949

5050
"PathEscape": url.PathEscape,
5151
"PathEscapeSegments": util.PathEscapeSegments,
@@ -59,9 +59,9 @@ func NewFuncMap() template.FuncMap {
5959
// svg / avatar / icon / color
6060
"svg": svg.RenderHTML,
6161
"EntryIcon": base.EntryIcon,
62-
"MigrationIcon": MigrationIcon,
63-
"ActionIcon": ActionIcon,
64-
"SortArrow": SortArrow,
62+
"MigrationIcon": migrationIcon,
63+
"ActionIcon": actionIcon,
64+
"SortArrow": sortArrow,
6565
"ContrastColor": util.ContrastColor,
6666

6767
// -----------------------------------------------------------------
@@ -139,7 +139,7 @@ func NewFuncMap() template.FuncMap {
139139
"DisableImportLocal": func() bool {
140140
return !setting.ImportLocalPaths
141141
},
142-
"UserThemeName": UserThemeName,
142+
"UserThemeName": userThemeName,
143143
"NotificationSettings": func() map[string]any {
144144
return map[string]any{
145145
"MinTimeout": int(setting.UI.Notification.MinTimeout / time.Millisecond),
@@ -155,28 +155,28 @@ func NewFuncMap() template.FuncMap {
155155
// -----------------------------------------------------------------
156156
// render
157157
"RenderCommitMessage": RenderCommitMessage,
158-
"RenderCommitMessageLinkSubject": RenderCommitMessageLinkSubject,
158+
"RenderCommitMessageLinkSubject": renderCommitMessageLinkSubject,
159159

160-
"RenderCommitBody": RenderCommitBody,
161-
"RenderCodeBlock": RenderCodeBlock,
162-
"RenderIssueTitle": RenderIssueTitle,
163-
"RenderEmoji": RenderEmoji,
164-
"ReactionToEmoji": ReactionToEmoji,
160+
"RenderCommitBody": renderCommitBody,
161+
"RenderCodeBlock": renderCodeBlock,
162+
"RenderIssueTitle": renderIssueTitle,
163+
"RenderEmoji": renderEmoji,
164+
"ReactionToEmoji": reactionToEmoji,
165165

166166
"RenderMarkdownToHtml": RenderMarkdownToHtml,
167-
"RenderLabel": RenderLabel,
167+
"RenderLabel": renderLabel,
168168
"RenderLabels": RenderLabels,
169169

170170
// -----------------------------------------------------------------
171171
// misc
172172
"ShortSha": base.ShortSha,
173173
"ActionContent2Commits": ActionContent2Commits,
174-
"IsMultilineCommitMessage": IsMultilineCommitMessage,
174+
"IsMultilineCommitMessage": isMultilineCommitMessage,
175175
"CommentMustAsDiff": gitdiff.CommentMustAsDiff,
176176
"MirrorRemoteAddress": mirrorRemoteAddress,
177177

178-
"FilenameIsImage": FilenameIsImage,
179-
"TabSizeClass": TabSizeClass,
178+
"FilenameIsImage": filenameIsImage,
179+
"TabSizeClass": tabSizeClass,
180180
}
181181
}
182182

@@ -197,8 +197,8 @@ func HTMLFormat(s string, rawArgs ...any) template.HTML {
197197
return template.HTML(fmt.Sprintf(s, args...))
198198
}
199199

200-
// SafeHTML render raw as HTML
201-
func SafeHTML(s any) template.HTML {
200+
// safeHTML render raw as HTML
201+
func safeHTML(s any) template.HTML {
202202
switch v := s.(type) {
203203
case string:
204204
return template.HTML(v)
@@ -213,7 +213,7 @@ func SanitizeHTML(s string) template.HTML {
213213
return template.HTML(markup.Sanitize(s))
214214
}
215215

216-
func HTMLEscape(s any) template.HTML {
216+
func htmlEscape(s any) template.HTML {
217217
switch v := s.(type) {
218218
case string:
219219
return template.HTML(html.EscapeString(v))
@@ -223,22 +223,22 @@ func HTMLEscape(s any) template.HTML {
223223
panic(fmt.Sprintf("unexpected type %T", s))
224224
}
225225

226-
func JSEscapeSafe(s string) template.HTML {
226+
func jsEscapeSafe(s string) template.HTML {
227227
return template.HTML(template.JSEscapeString(s))
228228
}
229229

230-
func QueryEscape(s string) template.URL {
230+
func queryEscape(s string) template.URL {
231231
return template.URL(url.QueryEscape(s))
232232
}
233233

234-
// DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls
235-
func DotEscape(raw string) string {
234+
// dotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent auto-linkers from detecting these as urls
235+
func dotEscape(raw string) string {
236236
return strings.ReplaceAll(raw, ".", "\u200d.\u200d")
237237
}
238238

239-
// Iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
240-
// and it could be simply used as "{{Iif expr trueVal}}" (omit the falseVal).
241-
func Iif(condition any, vals ...any) any {
239+
// iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
240+
// and it could be simply used as "{{iif expr trueVal}}" (omit the falseVal).
241+
func iif(condition any, vals ...any) any {
242242
if isTemplateTruthy(condition) {
243243
return vals[0]
244244
} else if len(vals) > 1 {
@@ -273,19 +273,19 @@ func isTemplateTruthy(v any) bool {
273273
}
274274
}
275275

276-
// Eval the expression and return the result, see the comment of eval.Expr for details.
276+
// evalTokens evaluates the expression by tokens and returns the result, see the comment of eval.Expr for details.
277277
// To use this helper function in templates, pass each token as a separate parameter.
278278
//
279279
// {{ $int64 := Eval $var "+" 1 }}
280280
// {{ $float64 := Eval $var "+" 1.0 }}
281281
//
282282
// Golang's template supports comparable int types, so the int64 result can be used in later statements like {{if lt $int64 10}}
283-
func Eval(tokens ...any) (any, error) {
283+
func evalTokens(tokens ...any) (any, error) {
284284
n, err := eval.Expr(tokens...)
285285
return n.Value, err
286286
}
287287

288-
func UserThemeName(user *user_model.User) string {
288+
func userThemeName(user *user_model.User) string {
289289
if user == nil || user.Theme == "" {
290290
return setting.UI.DefaultTheme
291291
}

Diff for: modules/templates/helper_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestSubjectBodySeparator(t *testing.T) {
5858
}
5959

6060
func TestJSEscapeSafe(t *testing.T) {
61-
assert.EqualValues(t, `\u0026\u003C\u003E\'\"`, JSEscapeSafe(`&<>'"`))
61+
assert.EqualValues(t, `\u0026\u003C\u003E\'\"`, jsEscapeSafe(`&<>'"`))
6262
}
6363

6464
func TestHTMLFormat(t *testing.T) {
@@ -71,8 +71,8 @@ func TestSanitizeHTML(t *testing.T) {
7171

7272
func TestTemplateTruthy(t *testing.T) {
7373
tmpl := template.New("test")
74-
tmpl.Funcs(template.FuncMap{"Iif": Iif})
75-
template.Must(tmpl.Parse(`{{if .Value}}true{{else}}false{{end}}:{{Iif .Value "true" "false"}}`))
74+
tmpl.Funcs(template.FuncMap{"iif": iif})
75+
template.Must(tmpl.Parse(`{{if .Value}}true{{else}}false{{end}}:{{iif .Value "true" "false"}}`))
7676

7777
cases := []any{
7878
nil, false, true, "", "string", 0, 1,

Diff for: modules/templates/mailer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}\s*$`)
2121
// mailSubjectTextFuncMap returns functions for injecting to text templates, it's only used for mail subject
2222
func mailSubjectTextFuncMap() texttmpl.FuncMap {
2323
return texttmpl.FuncMap{
24-
"dict": dict,
25-
"Eval": Eval,
24+
"dict": dict,
25+
"evalTokens": evalTokens,
2626

2727
"EllipsisString": base.EllipsisString,
2828
"AppName": func() string {

Diff for: modules/templates/util_misc.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/editorconfig/editorconfig-core-go/v2"
2525
)
2626

27-
func SortArrow(normSort, revSort, urlSort string, isDefault bool) template.HTML {
27+
func sortArrow(normSort, revSort, urlSort string, isDefault bool) template.HTML {
2828
// if needed
2929
if len(normSort) == 0 || len(urlSort) == 0 {
3030
return ""
@@ -50,8 +50,8 @@ func SortArrow(normSort, revSort, urlSort string, isDefault bool) template.HTML
5050
return ""
5151
}
5252

53-
// IsMultilineCommitMessage checks to see if a commit message contains multiple lines.
54-
func IsMultilineCommitMessage(msg string) bool {
53+
// isMultilineCommitMessage checks to see if a commit message contains multiple lines.
54+
func isMultilineCommitMessage(msg string) bool {
5555
return strings.Count(strings.TrimSpace(msg), "\n") >= 1
5656
}
5757

@@ -69,8 +69,8 @@ type Actioner interface {
6969
GetIssueInfos() []string
7070
}
7171

72-
// ActionIcon accepts an action operation type and returns an icon class name.
73-
func ActionIcon(opType activities_model.ActionType) string {
72+
// actionIcon accepts an action operation type and returns an icon class name.
73+
func actionIcon(opType activities_model.ActionType) string {
7474
switch opType {
7575
case activities_model.ActionCreateRepo, activities_model.ActionTransferRepo, activities_model.ActionRenameRepo:
7676
return "repo"
@@ -126,8 +126,8 @@ func ActionContent2Commits(act Actioner) *repository.PushCommits {
126126
return push
127127
}
128128

129-
// MigrationIcon returns a SVG name matching the service an issue/comment was migrated from
130-
func MigrationIcon(hostname string) string {
129+
// migrationIcon returns a SVG name matching the service an issue/comment was migrated from
130+
func migrationIcon(hostname string) string {
131131
switch hostname {
132132
case "github.com":
133133
return "octicon-mark-github"
@@ -177,12 +177,12 @@ func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteNa
177177
return ret
178178
}
179179

180-
func FilenameIsImage(filename string) bool {
180+
func filenameIsImage(filename string) bool {
181181
mimeType := mime.TypeByExtension(filepath.Ext(filename))
182182
return strings.HasPrefix(mimeType, "image/")
183183
}
184184

185-
func TabSizeClass(ec *editorconfig.Editorconfig, filename string) string {
185+
func tabSizeClass(ec *editorconfig.Editorconfig, filename string) string {
186186
if ec != nil {
187187
def, err := ec.GetDefinitionForFilename(filename)
188188
if err == nil && def.TabWidth >= 1 && def.TabWidth <= 16 {

Diff for: modules/templates/util_render.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ func RenderCommitMessage(ctx context.Context, msg string, metas map[string]strin
4141
if len(msgLines) == 0 {
4242
return template.HTML("")
4343
}
44-
return RenderCodeBlock(template.HTML(msgLines[0]))
44+
return renderCodeBlock(template.HTML(msgLines[0]))
4545
}
4646

47-
// RenderCommitMessageLinkSubject renders commit message as a XSS-safe link to
47+
// renderCommitMessageLinkSubject renders commit message as a XSS-safe link to
4848
// the provided default url, handling for special links without email to links.
49-
func RenderCommitMessageLinkSubject(ctx context.Context, msg, urlDefault string, metas map[string]string) template.HTML {
49+
func renderCommitMessageLinkSubject(ctx context.Context, msg, urlDefault string, metas map[string]string) template.HTML {
5050
msgLine := strings.TrimLeftFunc(msg, unicode.IsSpace)
5151
lineEnd := strings.IndexByte(msgLine, '\n')
5252
if lineEnd > 0 {
@@ -68,11 +68,11 @@ func RenderCommitMessageLinkSubject(ctx context.Context, msg, urlDefault string,
6868
log.Error("RenderCommitMessageSubject: %v", err)
6969
return template.HTML("")
7070
}
71-
return RenderCodeBlock(template.HTML(renderedMessage))
71+
return renderCodeBlock(template.HTML(renderedMessage))
7272
}
7373

74-
// RenderCommitBody extracts the body of a commit message without its title.
75-
func RenderCommitBody(ctx context.Context, msg string, metas map[string]string) template.HTML {
74+
// renderCommitBody extracts the body of a commit message without its title.
75+
func renderCommitBody(ctx context.Context, msg string, metas map[string]string) template.HTML {
7676
msgLine := strings.TrimSpace(msg)
7777
lineEnd := strings.IndexByte(msgLine, '\n')
7878
if lineEnd > 0 {
@@ -99,14 +99,14 @@ func RenderCommitBody(ctx context.Context, msg string, metas map[string]string)
9999
// Match text that is between back ticks.
100100
var codeMatcher = regexp.MustCompile("`([^`]+)`")
101101

102-
// RenderCodeBlock renders "`…`" as highlighted "<code>" block, intended for issue and PR titles
103-
func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
102+
// renderCodeBlock renders "`…`" as highlighted "<code>" block, intended for issue and PR titles
103+
func renderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
104104
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), `<code class="inline-code-block">$1</code>`) // replace with HTML <code> tags
105105
return template.HTML(htmlWithCodeTags)
106106
}
107107

108-
// RenderIssueTitle renders issue/pull title with defined post processors
109-
func RenderIssueTitle(ctx context.Context, text string, metas map[string]string) template.HTML {
108+
// renderIssueTitle renders issue/pull title with defined post processors
109+
func renderIssueTitle(ctx context.Context, text string, metas map[string]string) template.HTML {
110110
renderedText, err := markup.RenderIssueTitle(&markup.RenderContext{
111111
Ctx: ctx,
112112
Metas: metas,
@@ -118,9 +118,9 @@ func RenderIssueTitle(ctx context.Context, text string, metas map[string]string)
118118
return template.HTML(renderedText)
119119
}
120120

121-
// RenderLabel renders a label
121+
// renderLabel renders a label
122122
// locale is needed due to an import cycle with our context providing the `Tr` function
123-
func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_model.Label) template.HTML {
123+
func renderLabel(ctx context.Context, locale translation.Locale, label *issues_model.Label) template.HTML {
124124
var extraCSSClasses string
125125
textColor := util.ContrastColor(label.Color)
126126
labelScope := label.ExclusiveScope()
@@ -134,12 +134,12 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m
134134
if labelScope == "" {
135135
// Regular label
136136
return HTMLFormat(`<div class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s">%s</div>`,
137-
extraCSSClasses, textColor, label.Color, descriptionText, RenderEmoji(ctx, label.Name))
137+
extraCSSClasses, textColor, label.Color, descriptionText, renderEmoji(ctx, label.Name))
138138
}
139139

140140
// Scoped label
141-
scopeHTML := RenderEmoji(ctx, labelScope)
142-
itemHTML := RenderEmoji(ctx, label.Name[len(labelScope)+1:])
141+
scopeHTML := renderEmoji(ctx, labelScope)
142+
itemHTML := renderEmoji(ctx, label.Name[len(labelScope)+1:])
143143

144144
// Make scope and item background colors slightly darker and lighter respectively.
145145
// More contrast needed with higher luminance, empirically tweaked.
@@ -176,8 +176,8 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m
176176
textColor, itemColor, itemHTML)
177177
}
178178

179-
// RenderEmoji renders html text with emoji post processors
180-
func RenderEmoji(ctx context.Context, text string) template.HTML {
179+
// renderEmoji renders html text with emoji post processors
180+
func renderEmoji(ctx context.Context, text string) template.HTML {
181181
renderedText, err := markup.RenderEmoji(&markup.RenderContext{Ctx: ctx},
182182
template.HTMLEscapeString(text))
183183
if err != nil {
@@ -187,8 +187,8 @@ func RenderEmoji(ctx context.Context, text string) template.HTML {
187187
return template.HTML(renderedText)
188188
}
189189

190-
// ReactionToEmoji renders emoji for use in reactions
191-
func ReactionToEmoji(reaction string) template.HTML {
190+
// reactionToEmoji renders emoji for use in reactions
191+
func reactionToEmoji(reaction string) template.HTML {
192192
val := emoji.FromCode(reaction)
193193
if val != nil {
194194
return template.HTML(val.Emoji)
@@ -220,7 +220,7 @@ func RenderLabels(ctx context.Context, locale translation.Locale, labels []*issu
220220
if label == nil {
221221
continue
222222
}
223-
htmlCode += fmt.Sprintf(`<a href="%s?labels=%d">%s</a>`, baseLink, label.ID, RenderLabel(ctx, locale, label))
223+
htmlCode += fmt.Sprintf(`<a href="%s?labels=%d">%s</a>`, baseLink, label.ID, renderLabel(ctx, locale, label))
224224
}
225225
htmlCode += "</span>"
226226
return template.HTML(htmlCode)

Diff for: modules/templates/util_render_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestRenderCommitBody(t *testing.T) {
103103
}
104104
for _, tt := range tests {
105105
t.Run(tt.name, func(t *testing.T) {
106-
assert.Equalf(t, tt.want, RenderCommitBody(tt.args.ctx, tt.args.msg, tt.args.metas), "RenderCommitBody(%v, %v, %v)", tt.args.ctx, tt.args.msg, tt.args.metas)
106+
assert.Equalf(t, tt.want, renderCommitBody(tt.args.ctx, tt.args.msg, tt.args.metas), "RenderCommitBody(%v, %v, %v)", tt.args.ctx, tt.args.msg, tt.args.metas)
107107
})
108108
}
109109

@@ -127,7 +127,7 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
127127
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
128128
space`
129129

130-
assert.EqualValues(t, expected, RenderCommitBody(context.Background(), testInput(), testMetas))
130+
assert.EqualValues(t, expected, renderCommitBody(context.Background(), testInput(), testMetas))
131131
}
132132

133133
func TestRenderCommitMessage(t *testing.T) {
@@ -139,7 +139,7 @@ func TestRenderCommitMessage(t *testing.T) {
139139
func TestRenderCommitMessageLinkSubject(t *testing.T) {
140140
expected := `<a href="https://example.com/link" class="default-link muted">space </a><a href="/mention-user" class="mention">@mention-user</a>`
141141

142-
assert.EqualValues(t, expected, RenderCommitMessageLinkSubject(context.Background(), testInput(), "https://example.com/link", testMetas))
142+
assert.EqualValues(t, expected, renderCommitMessageLinkSubject(context.Background(), testInput(), "https://example.com/link", testMetas))
143143
}
144144

145145
func TestRenderIssueTitle(t *testing.T) {
@@ -165,7 +165,7 @@ [email protected]
165165
space<SPACE><SPACE>
166166
`
167167
expected = strings.ReplaceAll(expected, "<SPACE>", " ")
168-
assert.EqualValues(t, expected, RenderIssueTitle(context.Background(), testInput(), testMetas))
168+
assert.EqualValues(t, expected, renderIssueTitle(context.Background(), testInput(), testMetas))
169169
}
170170

171171
func TestRenderMarkdownToHtml(t *testing.T) {

0 commit comments

Comments
 (0)