Backport #37542 Co-authored-by: Nicolas <bircni@icloud.com> --------- Co-authored-by: Nicolas <bircni@icloud.com>
This commit is contained in:
@@ -37,11 +37,7 @@ type CommitSignature struct {
|
|||||||
|
|
||||||
// Message returns the commit message. Same as retrieving CommitMessage directly.
|
// Message returns the commit message. Same as retrieving CommitMessage directly.
|
||||||
func (c *Commit) Message() string {
|
func (c *Commit) Message() string {
|
||||||
// FIXME: GIT-COMMIT-MESSAGE-ENCODING: this logic is not right
|
return strings.ToValidUTF8(c.CommitMessage, "?")
|
||||||
// * When need to use commit message in templates/database, it should be valid UTF-8
|
|
||||||
// * When need to get the original commit message, it should just use "c.CommitMessage"
|
|
||||||
// It's not easy to refactor at the moment, many templates need to be updated and tested
|
|
||||||
return c.CommitMessage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary returns first line of commit message.
|
// Summary returns first line of commit message.
|
||||||
|
|||||||
@@ -159,6 +159,14 @@ ISO-8859-1`, commitFromReader.Signature.Payload)
|
|||||||
assert.Equal(t, commitFromReader, commitFromReader2)
|
assert.Equal(t, commitFromReader, commitFromReader2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCommitMessageSanitizesInvalidUTF8(t *testing.T) {
|
||||||
|
commit := &Commit{
|
||||||
|
CommitMessage: "title \xff\n\n\nbody \xff\n\n\n",
|
||||||
|
}
|
||||||
|
assert.Equal(t, "title ?\n\n\nbody ?\n\n\n", commit.Message())
|
||||||
|
assert.Equal(t, "title ?", commit.Summary())
|
||||||
|
}
|
||||||
|
|
||||||
func TestHasPreviousCommit(t *testing.T) {
|
func TestHasPreviousCommit(t *testing.T) {
|
||||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||||
@@ -102,7 +101,7 @@ func findLFSFileFunc(repo *git.Repository, objectID git.ObjectID, revListReader
|
|||||||
result := LFSResult{
|
result := LFSResult{
|
||||||
Name: curPath + string(fname),
|
Name: curPath + string(fname),
|
||||||
SHA: curCommit.ID.String(),
|
SHA: curCommit.ID.String(),
|
||||||
Summary: strings.Split(strings.TrimSpace(curCommit.CommitMessage), "\n")[0],
|
Summary: curCommit.Summary(),
|
||||||
When: curCommit.Author.When,
|
When: curCommit.Author.When,
|
||||||
ParentHashes: curCommit.Parents,
|
ParentHashes: curCommit.Parents,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ func renderBlameFillFirstBlameRow(repoLink string, avatarUtils *templates.Avatar
|
|||||||
br.PreviousSha = part.PreviousSha
|
br.PreviousSha = part.PreviousSha
|
||||||
br.PreviousShaURL = fmt.Sprintf("%s/blame/commit/%s/%s", repoLink, url.PathEscape(part.PreviousSha), util.PathEscapeSegments(part.PreviousPath))
|
br.PreviousShaURL = fmt.Sprintf("%s/blame/commit/%s/%s", repoLink, url.PathEscape(part.PreviousSha), util.PathEscapeSegments(part.PreviousPath))
|
||||||
br.CommitURL = fmt.Sprintf("%s/commit/%s", repoLink, url.PathEscape(part.Sha))
|
br.CommitURL = fmt.Sprintf("%s/commit/%s", repoLink, url.PathEscape(part.Sha))
|
||||||
br.CommitMessage = commit.CommitMessage
|
br.CommitMessage = commit.Message()
|
||||||
br.CommitSince = templates.TimeSince(commit.Author.When)
|
br.CommitSince = templates.TimeSince(commit.Author.When)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -435,7 +435,6 @@ func prepareNewPullRequestTitleContent(ci *git_service.CompareInfo, commits []*g
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(commits) == 1 {
|
if len(commits) == 1 {
|
||||||
// FIXME: GIT-COMMIT-MESSAGE-ENCODING: try to convert the encoding for commit message explicitly, ideally it should be done by a git commit struct method
|
|
||||||
c := commits[0]
|
c := commits[0]
|
||||||
_, content, _ = strings.Cut(strings.TrimSpace(c.UserCommit.CommitMessage), "\n")
|
_, content, _ = strings.Cut(strings.TrimSpace(c.UserCommit.CommitMessage), "\n")
|
||||||
content = strings.TrimSpace(content)
|
content = strings.TrimSpace(content)
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func TestNewPullRequestTitleContent(t *testing.T) {
|
|||||||
assert.Equal(t, "body", content)
|
assert.Equal(t, "body", content)
|
||||||
|
|
||||||
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("a\xf0\xf0\xf0\nb\xf0\xf0\xf0")})
|
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("a\xf0\xf0\xf0\nb\xf0\xf0\xf0")})
|
||||||
assert.Equal(t, "a?", title) // FIXME: GIT-COMMIT-MESSAGE-ENCODING: "title" doesn't use the same charset converting logic as "content"
|
assert.Equal(t, "a?", title)
|
||||||
assert.Equal(t, "b"+string(utf8.RuneError)+string(utf8.RuneError), content)
|
assert.Equal(t, "b"+string(utf8.RuneError)+string(utf8.RuneError), content)
|
||||||
|
|
||||||
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{
|
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ func handleWorkflows(
|
|||||||
|
|
||||||
for _, dwf := range detectedWorkflows {
|
for _, dwf := range detectedWorkflows {
|
||||||
run := &actions_model.ActionRun{
|
run := &actions_model.ActionRun{
|
||||||
Title: strings.SplitN(commit.CommitMessage, "\n", 2)[0],
|
Title: commit.Summary(),
|
||||||
RepoID: input.Repo.ID,
|
RepoID: input.Repo.ID,
|
||||||
Repo: input.Repo,
|
Repo: input.Repo,
|
||||||
OwnerID: input.Repo.OwnerID,
|
OwnerID: input.Repo.OwnerID,
|
||||||
@@ -483,7 +483,7 @@ func handleSchedules(
|
|||||||
}
|
}
|
||||||
|
|
||||||
run := &actions_model.ActionSchedule{
|
run := &actions_model.ActionSchedule{
|
||||||
Title: strings.SplitN(commit.CommitMessage, "\n", 2)[0],
|
Title: commit.Summary(),
|
||||||
RepoID: input.Repo.ID,
|
RepoID: input.Repo.ID,
|
||||||
Repo: input.Repo,
|
Repo: input.Repo,
|
||||||
OwnerID: input.Repo.OwnerID,
|
OwnerID: input.Repo.OwnerID,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package actions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
@@ -98,7 +97,7 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
|
|||||||
var entry *git.TreeEntry
|
var entry *git.TreeEntry
|
||||||
|
|
||||||
run := &actions_model.ActionRun{
|
run := &actions_model.ActionRun{
|
||||||
Title: strings.SplitN(runTargetCommit.CommitMessage, "\n", 2)[0],
|
Title: runTargetCommit.Summary(),
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
OwnerID: repo.OwnerID,
|
OwnerID: repo.OwnerID,
|
||||||
|
|||||||
@@ -154,10 +154,10 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||||||
|
|
||||||
// create a new pull request
|
// create a new pull request
|
||||||
if title == "" {
|
if title == "" {
|
||||||
title = strings.Split(commit.CommitMessage, "\n")[0]
|
title = commit.Summary()
|
||||||
}
|
}
|
||||||
if description == "" {
|
if description == "" {
|
||||||
_, description, _ = strings.Cut(commit.CommitMessage, "\n\n")
|
_, description, _ = strings.Cut(commit.Message(), "\n\n")
|
||||||
}
|
}
|
||||||
if description == "" {
|
if description == "" {
|
||||||
description = title
|
description = title
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag {
|
|||||||
|
|
||||||
return &api.Tag{
|
return &api.Tag{
|
||||||
Name: t.Name,
|
Name: t.Name,
|
||||||
Message: strings.TrimSpace(t.Message),
|
Message: strings.ToValidUTF8(strings.TrimSpace(t.Message), "?"), // the trim is not right, 1.27 won't trim
|
||||||
ID: t.ID.String(),
|
ID: t.ID.String(),
|
||||||
Commit: ToCommitMeta(repo, t),
|
Commit: ToCommitMeta(repo, t),
|
||||||
ZipballURL: zipballURL,
|
ZipballURL: zipballURL,
|
||||||
@@ -728,7 +728,7 @@ func ToAnnotatedTag(ctx context.Context, repo *repo_model.Repository, t *git.Tag
|
|||||||
Tag: t.Name,
|
Tag: t.Name,
|
||||||
SHA: t.ID.String(),
|
SHA: t.ID.String(),
|
||||||
Object: ToAnnotatedTagObject(repo, c),
|
Object: ToAnnotatedTagObject(repo, c),
|
||||||
Message: t.Message,
|
Message: strings.ToValidUTF8(t.Message, "?"),
|
||||||
URL: repo.APIURL() + "/git/tags/" + t.ID.String(),
|
URL: repo.APIURL() + "/git/tags/" + t.ID.String(),
|
||||||
Tagger: ToCommitUser(t.Tagger),
|
Tagger: ToCommitUser(t.Tagger),
|
||||||
Verification: ToVerification(ctx, c),
|
Verification: ToVerification(ctx, c),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func ToWikiCommit(commit *git.Commit) *api.WikiCommit {
|
|||||||
},
|
},
|
||||||
Date: commit.Committer.When.UTC().Format(time.RFC3339),
|
Date: commit.Committer.When.UTC().Format(time.RFC3339),
|
||||||
},
|
},
|
||||||
Message: commit.CommitMessage,
|
Message: commit.Message(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -847,7 +847,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
|
|||||||
maxMsgSize := setting.Repository.PullRequest.DefaultMergeMessageSize
|
maxMsgSize := setting.Repository.PullRequest.DefaultMergeMessageSize
|
||||||
for i := len(commits) - 1; i >= 0; i-- {
|
for i := len(commits) - 1; i >= 0; i-- {
|
||||||
commit := commits[i]
|
commit := commits[i]
|
||||||
msg := strings.TrimSpace(commit.CommitMessage)
|
msg := strings.TrimSpace(commit.Message())
|
||||||
if msg == "" {
|
if msg == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,7 +402,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
|||||||
}
|
}
|
||||||
|
|
||||||
rel, has := relMap[lowerTag]
|
rel, has := relMap[lowerTag]
|
||||||
title, note := git.SplitCommitTitleBody(tag.Message, 255)
|
title, note := git.SplitCommitTitleBody(strings.ToValidUTF8(tag.Message, "?"), 255)
|
||||||
if !has {
|
if !has {
|
||||||
rel = &repo_model.Release{
|
rel = &repo_model.Release{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user