Skip to content

Commit 9b8de2a

Browse files
committed
Merge branch 'main' into patch2
2 parents 1b34325 + 229235f commit 9b8de2a

Some content is hidden

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

59 files changed

+283
-106
lines changed

modules/htmlutil/html.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"html/template"
99
"slices"
10+
"strings"
1011
)
1112

1213
// ParseSizeAndClass get size and class from string with default values
@@ -31,6 +32,9 @@ func ParseSizeAndClass(defaultSize int, defaultClass string, others ...any) (int
3132
}
3233

3334
func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
35+
if !strings.Contains(string(s), "%") || len(rawArgs) == 0 {
36+
panic("HTMLFormat requires one or more arguments")
37+
}
3438
args := slices.Clone(rawArgs)
3539
for i, v := range args {
3640
switch v := v.(type) {

modules/markup/markdown/math/block_renderer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (r *BlockRenderer) writeLines(w util.BufWriter, source []byte, n gast.Node)
5151
func (r *BlockRenderer) renderBlock(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
5252
n := node.(*Block)
5353
if entering {
54-
code := giteaUtil.Iif(n.Inline, "", `<pre class="code-block is-loading">`) + `<code class="language-math display">`
55-
_ = r.renderInternal.FormatWithSafeAttrs(w, template.HTML(code))
54+
codeHTML := giteaUtil.Iif[template.HTML](n.Inline, "", `<pre class="code-block is-loading">`) + `<code class="language-math display">`
55+
_, _ = w.WriteString(string(r.renderInternal.ProtectSafeAttrs(codeHTML)))
5656
r.writeLines(w, source, n)
5757
} else {
5858
_, _ = w.WriteString(`</code>` + giteaUtil.Iif(n.Inline, "", `</pre>`) + "\n")

modules/markup/markdown/math/inline_renderer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewInlineRenderer(renderInternal *internal.RenderInternal) renderer.NodeRen
2828

2929
func (r *InlineRenderer) renderInline(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
3030
if entering {
31-
_ = r.renderInternal.FormatWithSafeAttrs(w, `<code class="language-math">`)
31+
_, _ = w.WriteString(string(r.renderInternal.ProtectSafeAttrs(`<code class="language-math">`)))
3232
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
3333
segment := c.(*ast.Text).Segment
3434
value := util.EscapeHTML(segment.Value(source))

modules/templates/helper.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package templates
66

77
import (
88
"fmt"
9-
"html"
109
"html/template"
1110
"net/url"
1211
"strconv"
@@ -38,9 +37,7 @@ func NewFuncMap() template.FuncMap {
3837
"dict": dict, // it's lowercase because this name has been widely used. Our other functions should have uppercase names.
3938
"Iif": iif,
4039
"Eval": evalTokens,
41-
"SafeHTML": safeHTML,
4240
"HTMLFormat": htmlFormat,
43-
"HTMLEscape": htmlEscape,
4441
"QueryEscape": queryEscape,
4542
"QueryBuild": QueryBuild,
4643
"JSEscape": jsEscapeSafe,
@@ -165,32 +162,11 @@ func NewFuncMap() template.FuncMap {
165162
}
166163
}
167164

168-
// safeHTML render raw as HTML
169-
func safeHTML(s any) template.HTML {
170-
switch v := s.(type) {
171-
case string:
172-
return template.HTML(v)
173-
case template.HTML:
174-
return v
175-
}
176-
panic(fmt.Sprintf("unexpected type %T", s))
177-
}
178-
179165
// SanitizeHTML sanitizes the input by default sanitization rules.
180166
func SanitizeHTML(s string) template.HTML {
181167
return markup.Sanitize(s)
182168
}
183169

184-
func htmlEscape(s any) template.HTML {
185-
switch v := s.(type) {
186-
case string:
187-
return template.HTML(html.EscapeString(v))
188-
case template.HTML:
189-
return v
190-
}
191-
panic(fmt.Sprintf("unexpected type %T", s))
192-
}
193-
194170
func htmlFormat(s any, args ...any) template.HTML {
195171
if len(args) == 0 {
196172
// to prevent developers from calling "HTMLFormat $userInput" by mistake which will lead to XSS

options/locale/locale_cs-CZ.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ editor.require_signed_commit=Větev vyžaduje podepsaný commit
13681368
editor.cherry_pick=Cherry-pick %s na:
13691369
editor.revert=Vrátit %s na:
13701370

1371+
13711372
commits.desc=Procházet historii změn zdrojového kódu.
13721373
commits.commits=Commity
13731374
commits.no_commits=Žádné společné commity. „%s“ a „%s“ mají zcela odlišnou historii.

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,6 @@ migrate.migrating_issues=Issues werden migriert
12281228
migrate.migrating_pulls=Pull Requests werden migriert
12291229
migrate.cancel_migrating_title=Migration abbrechen
12301230
migrate.cancel_migrating_confirm=Möchtest du diese Migration abbrechen?
1231-
migrating_status=Migrationstatus
12321231
12331232
mirror_from=Mirror von
12341233
forked_from=geforkt von
@@ -1392,6 +1391,7 @@ editor.require_signed_commit=Branch erfordert einen signierten Commit
13921391
editor.cherry_pick=Cherry-Picke %s von:
13931392
editor.revert=%s zurücksetzen auf:
13941393
1394+
13951395
commits.desc=Durchsuche die Quellcode-Änderungshistorie.
13961396
commits.commits=Commits
13971397
commits.no_commits=Keine gemeinsamen Commits. "%s" und "%s" haben vollständig unterschiedliche Historien.

options/locale/locale_el-GR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ editor.require_signed_commit=Ο κλάδος απαιτεί υπογεγραμμ
12261226
editor.cherry_pick=Ανθολόγηση (cherry-pic) του %s στο:
12271227
editor.revert=Απόσυρση του %s στο:
12281228

1229+
12291230
commits.desc=Δείτε το ιστορικό αλλαγών του πηγαίου κώδικα.
12301231
commits.commits=Υποβολές
12311232
commits.no_commits=Δεν υπάρχουν κοινές υποβολές. Τα "%s" και "%s" έχουν εντελώς διαφορετικές ιστορίες.

options/locale/locale_en-US.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ migrate.migrating_issues = Migrating Issues
12291229
migrate.migrating_pulls = Migrating Pull Requests
12301230
migrate.cancel_migrating_title = Cancel Migration
12311231
migrate.cancel_migrating_confirm = Do you want to cancel this migration?
1232-
migrating_status = Migrating status
1232+
migration_status = Migration status
12331233
12341234
mirror_from = mirror of
12351235
forked_from = forked from
@@ -3839,6 +3839,7 @@ runs.no_runs = The workflow has no runs yet.
38393839
runs.empty_commit_message = (empty commit message)
38403840
runs.expire_log_message = Logs have been purged because they were too old.
38413841
runs.delete = Delete workflow run
3842+
runs.cancel = Cancel workflow run
38423843
runs.delete.description = Are you sure you want to permanently delete this workflow run? This action cannot be undone.
38433844
runs.not_done = This workflow run is not done.
38443845
runs.view_workflow_file = View workflow file

options/locale/locale_es-ES.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ editor.require_signed_commit=Esta rama requiere un commit firmado
12161216
editor.cherry_pick=Hacer Cherry-pick %s en:
12171217
editor.revert=Revertir %s en:
12181218

1219+
12191220
commits.desc=Ver el historial de cambios de código fuente.
12201221
commits.commits=Commits
12211222
commits.no_commits=No hay commits en común. "%s" y "%s" tienen historias totalmente diferentes.

options/locale/locale_fa-IR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ editor.no_commit_to_branch=نمی‌توان به طور مستقیم درمور
949949
editor.user_no_push_to_branch=کاربر نمیتواند به شاخه ارسال کند
950950
editor.require_signed_commit=شاخه یک کامیت امضا شده لازم دارد
951951

952+
952953
commits.desc=تاریخچه تغییرات کد منبع را مرور کنید.
953954
commits.commits=کامیت‌ها
954955
commits.nothing_to_compare=این شاخه ها برابرند.

0 commit comments

Comments
 (0)