mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Fix commit message rendering and some UI problems (#34680)
* Fix #34679 * Fix #34676 * Fix #34674 * Fix #34526
This commit is contained in:
@@ -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: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style")
|
||||
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style\b))`)
|
||||
// cleans: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style", "<?", "<%")
|
||||
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style|%|\?)\b)`)
|
||||
v.nulCleaner = strings.NewReplacer("\000", "")
|
||||
return v
|
||||
})
|
||||
@@ -253,7 +253,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
|
||||
node, err := html.Parse(io.MultiReader(
|
||||
// prepend "<html><body>"
|
||||
strings.NewReader("<html><body>"),
|
||||
// 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("</body></html>"),
|
||||
|
@@ -525,6 +525,10 @@ func TestPostProcess(t *testing.T) {
|
||||
test("<script>a</script>", `<script>a</script>`)
|
||||
test("<STYLE>a", `<STYLE>a`)
|
||||
test("<style>a</STYLE>", `<style>a</STYLE>`)
|
||||
|
||||
// other special tags, our special behavior
|
||||
test("<?php\nfoo", "<?php\nfoo")
|
||||
test("<%asp\nfoo", "<%asp\nfoo")
|
||||
}
|
||||
|
||||
func TestIssue16020(t *testing.T) {
|
||||
|
@@ -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]))
|
||||
}
|
||||
|
Reference in New Issue
Block a user