From c7bacdc16c11aa53dd24088b4596716e970e35db Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 10 Jun 2025 18:27:42 +0800 Subject: [PATCH 1/4] fix --- models/renderhelper/repo_comment.go | 24 +++++++++++------------- models/renderhelper/repo_comment_test.go | 7 +++++++ modules/templates/util_render.go | 6 +++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/models/renderhelper/repo_comment.go b/models/renderhelper/repo_comment.go index a400f7b908a0f..ae0fbf0abd4d0 100644 --- a/models/renderhelper/repo_comment.go +++ b/models/renderhelper/repo_comment.go @@ -48,10 +48,7 @@ type RepoCommentOptions struct { } func NewRenderContextRepoComment(ctx context.Context, repo *repo_model.Repository, opts ...RepoCommentOptions) *markup.RenderContext { - helper := &RepoComment{ - repoLink: repo.Link(), - opts: util.OptionalArg(opts), - } + helper := &RepoComment{opts: util.OptionalArg(opts)} rctx := markup.NewRenderContext(ctx) helper.ctx = rctx var metas map[string]string @@ -60,15 +57,16 @@ func NewRenderContextRepoComment(ctx context.Context, repo *repo_model.Repositor helper.commitChecker = newCommitChecker(ctx, repo) metas = repo.ComposeCommentMetas(ctx) } else { - // this is almost dead code, only to pass the incorrect tests - helper.repoLink = fmt.Sprintf("%s/%s", helper.opts.DeprecatedOwnerName, helper.opts.DeprecatedRepoName) - rctx = rctx.WithMetas(map[string]string{ - "user": helper.opts.DeprecatedOwnerName, - "repo": helper.opts.DeprecatedRepoName, - - "markdownNewLineHardBreak": "true", - "markupAllowShortIssuePattern": "true", - }) + // repo can be nil when rendering a commit message in user's dashboard feedback whose repository has been deleted + metas = map[string]string{} + if helper.opts.DeprecatedOwnerName != "" { + // this is almost dead code, only to pass the incorrect tests + helper.repoLink = fmt.Sprintf("%s/%s", helper.opts.DeprecatedOwnerName, helper.opts.DeprecatedRepoName) + metas["user"] = helper.opts.DeprecatedOwnerName + metas["repo"] = helper.opts.DeprecatedRepoName + } + metas["markdownNewLineHardBreak"] = "true" + metas["markupAllowShortIssuePattern"] = "true" } metas["footnoteContextId"] = helper.opts.FootnoteContextID rctx = rctx.WithMetas(metas).WithHelper(helper) diff --git a/models/renderhelper/repo_comment_test.go b/models/renderhelper/repo_comment_test.go index 776152db96069..3b13bff73c7d5 100644 --- a/models/renderhelper/repo_comment_test.go +++ b/models/renderhelper/repo_comment_test.go @@ -72,4 +72,11 @@ func TestRepoComment(t *testing.T) { ./image

`, rendered) }) + + t.Run("NoRepo", func(t *testing.T) { + rctx := NewRenderContextRepoComment(t.Context(), nil).WithMarkupType(markdown.MarkupName) + rendered, err := markup.RenderString(rctx, "any") + assert.NoError(t, err) + assert.Equal(t, "

any

\n", rendered) + }) } diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 8d9ba1000c882..14655a53c3c5c 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -38,8 +38,8 @@ func NewRenderUtils(ctx reqctx.RequestContext) *RenderUtils { // RenderCommitMessage renders commit message with XSS-safe and special links. func (ut *RenderUtils) RenderCommitMessage(msg string, repo *repo.Repository) template.HTML { cleanMsg := template.HTMLEscapeString(msg) - // we can safely assume that it will not return any error, since there - // shouldn't be any special HTML. + // we can safely assume that it will not return any error, since there shouldn't be any special HTML. + // "repo" can be nil when rendering commit messages for deleted repositories in a user's dashboard feed. fullMessage, err := markup.PostProcessCommitMessage(renderhelper.NewRenderContextRepoComment(ut.ctx, repo), cleanMsg) if err != nil { log.Error("PostProcessCommitMessage: %v", err) @@ -47,7 +47,7 @@ func (ut *RenderUtils) RenderCommitMessage(msg string, repo *repo.Repository) te } msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") if len(msgLines) == 0 { - return template.HTML("") + return "" } return renderCodeBlock(template.HTML(msgLines[0])) } From 54fbd31d8d723cb35e9682fbc9dd847167bc5ec0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 10 Jun 2025 18:39:07 +0800 Subject: [PATCH 2/4] fix project text color --- web_src/css/repo/issue-card.css | 1 + 1 file changed, 1 insertion(+) diff --git a/web_src/css/repo/issue-card.css b/web_src/css/repo/issue-card.css index fb832bd05ab0f..27f3c2d554e60 100644 --- a/web_src/css/repo/issue-card.css +++ b/web_src/css/repo/issue-card.css @@ -7,6 +7,7 @@ padding: 8px 10px; border: 1px solid var(--color-secondary); background: var(--color-card); + color: var(--color-text); /* it can't inherit from parent because the card already has its own background */ } .issue-card-icon, From 01f2996e7e96daed072ad268b95d7e9f081725cb Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 10 Jun 2025 18:43:39 +0800 Subject: [PATCH 3/4] fix "run workflow" dropdown focus --- templates/repo/actions/workflow_dispatch_inputs.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/repo/actions/workflow_dispatch_inputs.tmpl b/templates/repo/actions/workflow_dispatch_inputs.tmpl index 8b8292af1d84e..37538a318f824 100644 --- a/templates/repo/actions/workflow_dispatch_inputs.tmpl +++ b/templates/repo/actions/workflow_dispatch_inputs.tmpl @@ -33,7 +33,8 @@ {{end}}
- + {{/* use autofocus here to prevent the "branch selection" dropdown from getting focus, otherwise it will auto popup */}} +
{{end}} {{range .workflows}} From e6dcbd261561694187c7b9b67fd82e01dc079978 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 10 Jun 2025 19:51:21 +0800 Subject: [PATCH 4/4] fix html in markdown --- modules/markup/html.go | 6 +++--- modules/markup/html_test.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index d45153d95b85f..e8391341d90e5 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -86,8 +86,8 @@ var globalVars = sync.OnceValue(func() *globalVarsType { // codePreviewPattern matches "http://domain/.../{owner}/{repo}/src/commit/{commit}/{filepath}#L10-L20" v.codePreviewPattern = regexp.MustCompile(`https?://\S+/([^\s/]+)/([^\s/]+)/src/commit/([0-9a-f]{7,64})(/\S+)#(L\d+(-L\d+)?)`) - // cleans: "" strings.NewReader(""), - // Strip out nuls - they're always invalid + // strip out NULLs (they're always invalid), and escape known tags bytes.NewReader(globalVars().tagCleaner.ReplaceAll([]byte(globalVars().nulCleaner.Replace(string(rawHTML))), []byte("<$1"))), // close the tags strings.NewReader(""), diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 58f71bdd7b581..5fdbf43f7cb22 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -525,6 +525,10 @@ func TestPostProcess(t *testing.T) { test("", `<script>a</script>`) test("", `<style>a</STYLE>`) + + // other special tags, our special behavior + test("