Skip to content

Commit 1610a63

Browse files
authored
Fix commit message rendering and some UI problems (#34680)
* Fix #34679 * Fix #34676 * Fix #34674 * Fix #34526
1 parent e9f5105 commit 1610a63

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

models/renderhelper/repo_comment.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ type RepoCommentOptions struct {
4848
}
4949

5050
func NewRenderContextRepoComment(ctx context.Context, repo *repo_model.Repository, opts ...RepoCommentOptions) *markup.RenderContext {
51-
helper := &RepoComment{
52-
repoLink: repo.Link(),
53-
opts: util.OptionalArg(opts),
54-
}
51+
helper := &RepoComment{opts: util.OptionalArg(opts)}
5552
rctx := markup.NewRenderContext(ctx)
5653
helper.ctx = rctx
5754
var metas map[string]string
@@ -60,15 +57,16 @@ func NewRenderContextRepoComment(ctx context.Context, repo *repo_model.Repositor
6057
helper.commitChecker = newCommitChecker(ctx, repo)
6158
metas = repo.ComposeCommentMetas(ctx)
6259
} else {
63-
// this is almost dead code, only to pass the incorrect tests
64-
helper.repoLink = fmt.Sprintf("%s/%s", helper.opts.DeprecatedOwnerName, helper.opts.DeprecatedRepoName)
65-
rctx = rctx.WithMetas(map[string]string{
66-
"user": helper.opts.DeprecatedOwnerName,
67-
"repo": helper.opts.DeprecatedRepoName,
68-
69-
"markdownNewLineHardBreak": "true",
70-
"markupAllowShortIssuePattern": "true",
71-
})
60+
// repo can be nil when rendering a commit message in user's dashboard feedback whose repository has been deleted
61+
metas = map[string]string{}
62+
if helper.opts.DeprecatedOwnerName != "" {
63+
// this is almost dead code, only to pass the incorrect tests
64+
helper.repoLink = fmt.Sprintf("%s/%s", helper.opts.DeprecatedOwnerName, helper.opts.DeprecatedRepoName)
65+
metas["user"] = helper.opts.DeprecatedOwnerName
66+
metas["repo"] = helper.opts.DeprecatedRepoName
67+
}
68+
metas["markdownNewLineHardBreak"] = "true"
69+
metas["markupAllowShortIssuePattern"] = "true"
7270
}
7371
metas["footnoteContextId"] = helper.opts.FootnoteContextID
7472
rctx = rctx.WithMetas(metas).WithHelper(helper)

models/renderhelper/repo_comment_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,11 @@ func TestRepoComment(t *testing.T) {
7272
<a href="/user2/repo1/commit/1234/image" target="_blank" rel="nofollow noopener"><img src="/user2/repo1/commit/1234/image" alt="./image"/></a></p>
7373
`, rendered)
7474
})
75+
76+
t.Run("NoRepo", func(t *testing.T) {
77+
rctx := NewRenderContextRepoComment(t.Context(), nil).WithMarkupType(markdown.MarkupName)
78+
rendered, err := markup.RenderString(rctx, "any")
79+
assert.NoError(t, err)
80+
assert.Equal(t, "<p>any</p>\n", rendered)
81+
})
7582
}

modules/markup/html.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ var globalVars = sync.OnceValue(func() *globalVarsType {
8686
// codePreviewPattern matches "http://domain/.../{owner}/{repo}/src/commit/{commit}/{filepath}#L10-L20"
8787
v.codePreviewPattern = regexp.MustCompile(`https?://\S+/([^\s/]+)/([^\s/]+)/src/commit/([0-9a-f]{7,64})(/\S+)#(L\d+(-L\d+)?)`)
8888

89-
// cleans: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style")
90-
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style\b))`)
89+
// cleans: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style", "<?", "<%")
90+
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style|%|\?)\b)`)
9191
v.nulCleaner = strings.NewReplacer("\000", "")
9292
return v
9393
})
@@ -253,7 +253,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
253253
node, err := html.Parse(io.MultiReader(
254254
// prepend "<html><body>"
255255
strings.NewReader("<html><body>"),
256-
// Strip out nuls - they're always invalid
256+
// strip out NULLs (they're always invalid), and escape known tags
257257
bytes.NewReader(globalVars().tagCleaner.ReplaceAll([]byte(globalVars().nulCleaner.Replace(string(rawHTML))), []byte("&lt;$1"))),
258258
// close the tags
259259
strings.NewReader("</body></html>"),

modules/markup/html_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ func TestPostProcess(t *testing.T) {
525525
test("<script>a</script>", `&lt;script&gt;a&lt;/script&gt;`)
526526
test("<STYLE>a", `&lt;STYLE&gt;a`)
527527
test("<style>a</STYLE>", `&lt;style&gt;a&lt;/STYLE&gt;`)
528+
529+
// other special tags, our special behavior
530+
test("<?php\nfoo", "&lt;?php\nfoo")
531+
test("<%asp\nfoo", "&lt;%asp\nfoo")
528532
}
529533

530534
func TestIssue16020(t *testing.T) {

modules/templates/util_render.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ func NewRenderUtils(ctx reqctx.RequestContext) *RenderUtils {
3838
// RenderCommitMessage renders commit message with XSS-safe and special links.
3939
func (ut *RenderUtils) RenderCommitMessage(msg string, repo *repo.Repository) template.HTML {
4040
cleanMsg := template.HTMLEscapeString(msg)
41-
// we can safely assume that it will not return any error, since there
42-
// shouldn't be any special HTML.
41+
// we can safely assume that it will not return any error, since there shouldn't be any special HTML.
42+
// "repo" can be nil when rendering commit messages for deleted repositories in a user's dashboard feed.
4343
fullMessage, err := markup.PostProcessCommitMessage(renderhelper.NewRenderContextRepoComment(ut.ctx, repo), cleanMsg)
4444
if err != nil {
4545
log.Error("PostProcessCommitMessage: %v", err)
4646
return ""
4747
}
4848
msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n")
4949
if len(msgLines) == 0 {
50-
return template.HTML("")
50+
return ""
5151
}
5252
return renderCodeBlock(template.HTML(msgLines[0]))
5353
}

templates/repo/actions/workflow_dispatch_inputs.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
</div>
3434
{{end}}
3535
<div class="ui field">
36-
<button class="ui tiny primary button" type="submit">{{ctx.Locale.Tr "actions.workflow.run"}}</button>
36+
{{/* use autofocus here to prevent the "branch selection" dropdown from getting focus, otherwise it will auto popup */}}
37+
<button class="ui tiny primary button" autofocus type="submit">{{ctx.Locale.Tr "actions.workflow.run"}}</button>
3738
</div>
3839
{{end}}
3940
{{range .workflows}}

web_src/css/repo/issue-card.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
padding: 8px 10px;
88
border: 1px solid var(--color-secondary);
99
background: var(--color-card);
10+
color: var(--color-text); /* it can't inherit from parent because the card already has its own background */
1011
}
1112

1213
.issue-card-icon,

0 commit comments

Comments
 (0)