Skip to content

Commit 7802bb0

Browse files
authored
Merge branch 'main' into fix-comment-form
2 parents 228ee23 + a797b84 commit 7802bb0

File tree

358 files changed

+484
-375
lines changed

Some content is hidden

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

358 files changed

+484
-375
lines changed

build/generate-svg.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ async function processFile(file, {prefix, fullName} = {}) {
2525
if (prefix === 'octicon') name = name.replace(/-[0-9]+$/, ''); // chop of '-16' on octicons
2626
}
2727

28+
// Set the `xmlns` attribute so that the files are displayable in standalone documents
29+
// The svg backend module will strip the attribute during startup for inline display
2830
const {data} = optimize(await readFile(file, 'utf8'), {
2931
plugins: [
3032
{name: 'preset-default'},
31-
{name: 'removeXMLNS'},
3233
{name: 'removeDimensions'},
3334
{name: 'prefixIds', params: {prefix: () => name}},
3435
{name: 'addClassesToSVGElement', params: {classNames: ['svg', name]}},
35-
{name: 'addAttributesToSVGElement', params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]}},
36+
{
37+
name: 'addAttributesToSVGElement', params: {
38+
attributes: [
39+
{'xmlns': 'http://www.w3.org/2000/svg'},
40+
{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'},
41+
]
42+
}
43+
},
3644
],
3745
});
3846

modules/context/context.go

+32
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
"net/http"
1717
"net/url"
1818
"path"
19+
"regexp"
1920
"strconv"
2021
"strings"
22+
texttemplate "text/template"
2123
"time"
2224

2325
"code.gitea.io/gitea/models/db"
@@ -213,6 +215,8 @@ func (ctx *Context) RedirectToFirst(location ...string) {
213215
ctx.Redirect(setting.AppSubURL + "/")
214216
}
215217

218+
var templateExecutingErr = regexp.MustCompile(`^template: (.*):([1-9][0-9]*):([1-9][0-9]*): executing (?:"(.*)" at <(.*)>: )?`)
219+
216220
// HTML calls Context.HTML and renders the template to HTTP response
217221
func (ctx *Context) HTML(status int, name base.TplName) {
218222
log.Debug("Template: %s", name)
@@ -228,6 +232,34 @@ func (ctx *Context) HTML(status int, name base.TplName) {
228232
ctx.PlainText(http.StatusInternalServerError, "Unable to find status/500 template")
229233
return
230234
}
235+
if execErr, ok := err.(texttemplate.ExecError); ok {
236+
if groups := templateExecutingErr.FindStringSubmatch(err.Error()); len(groups) > 0 {
237+
errorTemplateName, lineStr, posStr := groups[1], groups[2], groups[3]
238+
target := ""
239+
if len(groups) == 6 {
240+
target = groups[5]
241+
}
242+
line, _ := strconv.Atoi(lineStr) // Cannot error out as groups[2] is [1-9][0-9]*
243+
pos, _ := strconv.Atoi(posStr) // Cannot error out as groups[3] is [1-9][0-9]*
244+
filename, filenameErr := templates.GetAssetFilename("templates/" + errorTemplateName + ".tmpl")
245+
if filenameErr != nil {
246+
filename = "(template) " + errorTemplateName
247+
}
248+
if errorTemplateName != string(name) {
249+
filename += " (subtemplate of " + string(name) + ")"
250+
}
251+
err = fmt.Errorf("%w\nin template file %s:\n%s", err, filename, templates.GetLineFromTemplate(errorTemplateName, line, target, pos))
252+
} else {
253+
filename, filenameErr := templates.GetAssetFilename("templates/" + execErr.Name + ".tmpl")
254+
if filenameErr != nil {
255+
filename = "(template) " + execErr.Name
256+
}
257+
if execErr.Name != string(name) {
258+
filename += " (subtemplate of " + string(name) + ")"
259+
}
260+
err = fmt.Errorf("%w\nin template file %s", err, filename)
261+
}
262+
}
231263
ctx.ServerError("Render failed", err)
232264
}
233265
}

modules/svg/svg.go

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const defaultSize = 16
2525
// Init discovers SVGs and populates the `SVGs` variable
2626
func Init() {
2727
SVGs = Discover()
28+
29+
// Remove `xmlns` because inline SVG does not need it
30+
r := regexp.MustCompile(`(<svg\b[^>]*?)\s+xmlns="[^"]*"`)
31+
for name, svg := range SVGs {
32+
SVGs[name] = r.ReplaceAllString(svg, "$1")
33+
}
2834
}
2935

3036
// Render render icons - arguments icon name (string), size (int), class (string)

modules/templates/htmlrenderer.go

+25-18
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func handleGenericTemplateError(err error) (string, []interface{}) {
118118

119119
lineNumber, _ := strconv.Atoi(lineNumberStr)
120120

121-
line := getLineFromAsset(templateName, lineNumber, "")
121+
line := GetLineFromTemplate(templateName, lineNumber, "", -1)
122122

123123
return "PANIC: Unable to compile templates!\n%s in template file %s at line %d:\n\n%s\nStacktrace:\n\n%s", []interface{}{message, filename, lineNumber, log.NewColoredValue(line, log.Reset), log.Stack(2)}
124124
}
@@ -140,7 +140,7 @@ func handleNotDefinedPanicError(err error) (string, []interface{}) {
140140

141141
lineNumber, _ := strconv.Atoi(lineNumberStr)
142142

143-
line := getLineFromAsset(templateName, lineNumber, functionName)
143+
line := GetLineFromTemplate(templateName, lineNumber, functionName, -1)
144144

145145
return "PANIC: Unable to compile templates!\nUndefined function %q in template file %s at line %d:\n\n%s", []interface{}{functionName, filename, lineNumber, log.NewColoredValue(line, log.Reset)}
146146
}
@@ -161,7 +161,7 @@ func handleUnexpected(err error) (string, []interface{}) {
161161

162162
lineNumber, _ := strconv.Atoi(lineNumberStr)
163163

164-
line := getLineFromAsset(templateName, lineNumber, unexpected)
164+
line := GetLineFromTemplate(templateName, lineNumber, unexpected, -1)
165165

166166
return "PANIC: Unable to compile templates!\nUnexpected %q in template file %s at line %d:\n\n%s", []interface{}{unexpected, filename, lineNumber, log.NewColoredValue(line, log.Reset)}
167167
}
@@ -181,14 +181,15 @@ func handleExpectedEnd(err error) (string, []interface{}) {
181181

182182
lineNumber, _ := strconv.Atoi(lineNumberStr)
183183

184-
line := getLineFromAsset(templateName, lineNumber, unexpected)
184+
line := GetLineFromTemplate(templateName, lineNumber, unexpected, -1)
185185

186186
return "PANIC: Unable to compile templates!\nMissing end with unexpected %q in template file %s at line %d:\n\n%s", []interface{}{unexpected, filename, lineNumber, log.NewColoredValue(line, log.Reset)}
187187
}
188188

189189
const dashSeparator = "----------------------------------------------------------------------\n"
190190

191-
func getLineFromAsset(templateName string, targetLineNum int, target string) string {
191+
// GetLineFromTemplate returns a line from a template with some context
192+
func GetLineFromTemplate(templateName string, targetLineNum int, target string, position int) string {
192193
bs, err := GetAsset("templates/" + templateName + ".tmpl")
193194
if err != nil {
194195
return fmt.Sprintf("(unable to read template file: %v)", err)
@@ -229,23 +230,29 @@ func getLineFromAsset(templateName string, targetLineNum int, target string) str
229230
// If there is a provided target to look for in the line add a pointer to it
230231
// e.g. ^^^^^^^
231232
if target != "" {
232-
idx := bytes.Index(lineBs, []byte(target))
233-
234-
if idx >= 0 {
235-
// take the current line and replace preceding text with whitespace (except for tab)
236-
for i := range lineBs[:idx] {
237-
if lineBs[i] != '\t' {
238-
lineBs[i] = ' '
239-
}
233+
targetPos := bytes.Index(lineBs, []byte(target))
234+
if targetPos >= 0 {
235+
position = targetPos
236+
}
237+
}
238+
if position >= 0 {
239+
// take the current line and replace preceding text with whitespace (except for tab)
240+
for i := range lineBs[:position] {
241+
if lineBs[i] != '\t' {
242+
lineBs[i] = ' '
240243
}
244+
}
241245

242-
// write the preceding "space"
243-
_, _ = sb.Write(lineBs[:idx])
246+
// write the preceding "space"
247+
_, _ = sb.Write(lineBs[:position])
244248

245-
// Now write the ^^ pointer
246-
_, _ = sb.WriteString(strings.Repeat("^", len(target)))
247-
_ = sb.WriteByte('\n')
249+
// Now write the ^^ pointer
250+
targetLen := len(target)
251+
if targetLen == 0 {
252+
targetLen = 1
248253
}
254+
_, _ = sb.WriteString(strings.Repeat("^", targetLen))
255+
_ = sb.WriteByte('\n')
249256
}
250257

251258
// Finally write the footer

options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,9 @@ diff.review.header = Submit review
22652265
diff.review.placeholder = Review comment
22662266
diff.review.comment = Comment
22672267
diff.review.approve = Approve
2268+
diff.review.self_reject = Pull request authors can't request changes on their own pull request
22682269
diff.review.reject = Request changes
2270+
diff.review.self_approve = Pull request authors can't approve their own pull request
22692271
diff.committed_by = committed by
22702272
diff.protected = Protected
22712273
diff.image.side_by_side = Side by Side

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
1616
"@primer/octicons": "18.2.0",
1717
"@vue/compiler-sfc": "3.2.47",
18+
"@webcomponents/custom-elements": "1.5.1",
1819
"add-asset-webpack-plugin": "2.0.1",
1920
"ansi-to-html": "0.7.2",
2021
"asciinema-player": "3.2.0",

public/img/svg/fontawesome-openid.svg

+1-1
Loading

public/img/svg/fontawesome-save.svg

+1-1
Loading

public/img/svg/fontawesome-send.svg

+1-1
Loading
+1-1
Loading

public/img/svg/gitea-cargo.svg

+1-1
Loading

0 commit comments

Comments
 (0)