diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-11-14 08:19:14 +0100 |
---|---|---|
committer | Earl Warren <contact@earl-warren.org> | 2024-11-17 12:18:56 +0100 |
commit | c2e8790df37a14b4d2f72c7377db75309e0ebf1d (patch) | |
tree | 278933355e3a110f0ca356a61fe428e170aca203 /models/issues | |
parent | Fix nil panic if repo doesn't exist (#32501) (diff) | |
download | forgejo-c2e8790df37a14b4d2f72c7377db75309e0ebf1d.tar.xz forgejo-c2e8790df37a14b4d2f72c7377db75309e0ebf1d.zip |
Trim title before insert/update to database to match the size requirements of database (#32498)
Fix #32489
(cherry picked from commit 98d9a71ffe510da0e10d042d8f87a348022aca87)
Diffstat (limited to 'models/issues')
-rw-r--r-- | models/issues/issue_update.go | 4 | ||||
-rw-r--r-- | models/issues/pull.go | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go index dbfd2fc91b..31c8bdc17b 100644 --- a/models/issues/issue_update.go +++ b/models/issues/issue_update.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/references" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/util" "xorm.io/builder" ) @@ -154,6 +155,7 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User, } defer committer.Close() + issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255) if err = UpdateIssueCols(ctx, issue, "name"); err != nil { return fmt.Errorf("updateIssueCols: %w", err) } @@ -409,6 +411,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue } // NewIssue creates new issue with labels for repository. +// The title will be cut off at 255 characters if it's longer than 255 characters. func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) { ctx, committer, err := db.TxContext(ctx) if err != nil { @@ -422,6 +425,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la } issue.Index = idx + issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255) if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{ Repo: repo, diff --git a/models/issues/pull.go b/models/issues/pull.go index e7663ea350..13eafccdc7 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -566,6 +566,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *Iss } issue.Index = idx + issue.Title, _ = util.SplitStringAtByteN(issue.Title, 255) if err = NewIssueWithIndex(ctx, issue.Poster, NewIssueOptions{ Repo: repo, |