From 8351172b6e5221290dc5b2c81e159e2eec0b43c8 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 16 Sep 2022 09:19:16 +0200 Subject: [PATCH 1/7] Limit length of repo description and repo url input fields (#21119) Both allow only limited characters. If you input more, you will get a error message. So it make sense to limit the characters of the input fields. Slightly relax the MaxSize of repo's Description and Website --- modules/structs/repo.go | 10 +++++----- services/forms/repo_form.go | 8 ++++---- templates/repo/settings/options.tmpl | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 6a5736898d139..d3833105d7269 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -111,7 +111,7 @@ type CreateRepoOption struct { // unique: true Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"` // Description of the repository to create - Description string `json:"description" binding:"MaxSize(255)"` + Description string `json:"description" binding:"MaxSize(2048)"` // Whether the repository is private Private bool `json:"private"` // Label-Set to use @@ -140,9 +140,9 @@ type EditRepoOption struct { // unique: true Name *string `json:"name,omitempty" binding:"OmitEmpty;AlphaDashDot;MaxSize(100);"` // a short description of the repository. - Description *string `json:"description,omitempty" binding:"MaxSize(255)"` + Description *string `json:"description,omitempty" binding:"MaxSize(2048)"` // a URL with more information about the repository. - Website *string `json:"website,omitempty" binding:"MaxSize(255)"` + Website *string `json:"website,omitempty" binding:"MaxSize(1024)"` // either `true` to make the repository private or `false` to make it public. // Note: you will get a 422 error if the organization restricts changing repository visibility to organization // owners and a non-owner tries to change the value of private. @@ -208,7 +208,7 @@ type GenerateRepoOption struct { // Default branch of the new repository DefaultBranch string `json:"default_branch"` // Description of the repository to create - Description string `json:"description" binding:"MaxSize(255)"` + Description string `json:"description" binding:"MaxSize(2048)"` // Whether the repository is private Private bool `json:"private"` // include git content of default branch in template repo @@ -316,7 +316,7 @@ type MigrateRepoOptions struct { LFS bool `json:"lfs"` LFSEndpoint string `json:"lfs_endpoint"` Private bool `json:"private"` - Description string `json:"description" binding:"MaxSize(255)"` + Description string `json:"description" binding:"MaxSize(2048)"` Wiki bool `json:"wiki"` Milestones bool `json:"milestones"` Labels bool `json:"labels"` diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 4eb20d297f203..c1e9cb3197c0b 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -34,7 +34,7 @@ type CreateRepoForm struct { UID int64 `binding:"Required"` RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` Private bool - Description string `binding:"MaxSize(255)"` + Description string `binding:"MaxSize(2048)"` DefaultBranch string `binding:"GitRefName;MaxSize(100)"` AutoInit bool Gitignores string @@ -76,7 +76,7 @@ type MigrateRepoForm struct { LFS bool `json:"lfs"` LFSEndpoint string `json:"lfs_endpoint"` Private bool `json:"private"` - Description string `json:"description" binding:"MaxSize(255)"` + Description string `json:"description" binding:"MaxSize(2048)"` Wiki bool `json:"wiki"` Milestones bool `json:"milestones"` Labels bool `json:"labels"` @@ -116,8 +116,8 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err // RepoSettingForm form for changing repository settings type RepoSettingForm struct { RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` - Description string `binding:"MaxSize(255)"` - Website string `binding:"ValidUrl;MaxSize(255)"` + Description string `binding:"MaxSize(2048)"` + Website string `binding:"ValidUrl;MaxSize(1024)"` Interval string MirrorAddress string MirrorUsername string diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index a9ceebd446094..0214df4514920 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -42,11 +42,11 @@ {{end}}
- +
- +
From 548387b2beaaaeb6b1c32c3c6f226b8f53aafecb Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 16 Sep 2022 14:44:00 +0200 Subject: [PATCH 2/7] Show label description in comments section (#21156) The labels in the comment section are currently missing the description that all other labels have. --- modules/templates/helper.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 2879d68e3b888..a8e4075248dd8 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -377,17 +377,17 @@ func NewFuncMap() []template.FuncMap { return "" }, "RenderLabels": func(labels []*issues_model.Label, repoLink string) template.HTML { - html := `` + htmlCode := `` for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so if label == nil { continue } - html += fmt.Sprintf("%s ", - repoLink, label.ID, label.ForegroundColor(), label.Color, RenderEmoji(label.Name)) + htmlCode += fmt.Sprintf("%s ", + repoLink, label.ID, label.ForegroundColor(), label.Color, html.EscapeString(label.Description), RenderEmoji(label.Name)) } - html += "" - return template.HTML(html) + htmlCode += "" + return template.HTML(htmlCode) }, "MermaidMaxSourceCharacters": func() int { return setting.MermaidMaxSourceCharacters From 43c10def6849f0e1ea50a52115360e6be50ad1ab Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sat, 17 Sep 2022 04:45:32 +0200 Subject: [PATCH 3/7] Fix CSV diff for added/deleted files (#21189) Fixes #21184 Regression of #19552 Instead of using `GetBlobByPath` I use the already existing instances. We need more information from #19530 if that error is still present. --- routers/web/repo/compare.go | 36 +++++++++++++++---------------- templates/repo/diff/box.tmpl | 2 +- templates/repo/diff/csv_diff.tmpl | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index e35af31724fdf..e7e68d3c5e92d 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -112,17 +112,17 @@ func setCsvCompareContext(ctx *context.Context) { Error string } - ctx.Data["CreateCsvDiff"] = func(diffFile *gitdiff.DiffFile, baseCommit, headCommit *git.Commit) CsvDiffResult { - if diffFile == nil || baseCommit == nil || headCommit == nil { + ctx.Data["CreateCsvDiff"] = func(diffFile *gitdiff.DiffFile, baseBlob, headBlob *git.Blob) CsvDiffResult { + if diffFile == nil { return CsvDiffResult{nil, ""} } errTooLarge := errors.New(ctx.Locale.Tr("repo.error.csv.too_large")) - csvReaderFromCommit := func(ctx *markup.RenderContext, c *git.Commit) (*csv.Reader, io.Closer, error) { - blob, err := c.GetBlobByPath(diffFile.Name) - if err != nil { - return nil, nil, err + csvReaderFromCommit := func(ctx *markup.RenderContext, blob *git.Blob) (*csv.Reader, io.Closer, error) { + if blob == nil { + // It's ok for blob to be nil (file added or deleted) + return nil, nil, nil } if setting.UI.CSV.MaxFileSize != 0 && setting.UI.CSV.MaxFileSize < blob.Size() { @@ -138,28 +138,28 @@ func setCsvCompareContext(ctx *context.Context) { return csvReader, reader, err } - baseReader, baseBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.OldName}, baseCommit) + baseReader, baseBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.OldName}, baseBlob) if baseBlobCloser != nil { defer baseBlobCloser.Close() } - if err == errTooLarge { - return CsvDiffResult{nil, err.Error()} - } if err != nil { - log.Error("CreateCsvDiff error whilst creating baseReader from file %s in commit %s in %s: %v", diffFile.Name, baseCommit.ID.String(), ctx.Repo.Repository.Name, err) - return CsvDiffResult{nil, "unable to load file from base commit"} + if err == errTooLarge { + return CsvDiffResult{nil, err.Error()} + } + log.Error("error whilst creating csv.Reader from file %s in base commit %s in %s: %v", diffFile.Name, baseBlob.ID.String(), ctx.Repo.Repository.Name, err) + return CsvDiffResult{nil, "unable to load file"} } - headReader, headBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.Name}, headCommit) + headReader, headBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.Name}, headBlob) if headBlobCloser != nil { defer headBlobCloser.Close() } - if err == errTooLarge { - return CsvDiffResult{nil, err.Error()} - } if err != nil { - log.Error("CreateCsvDiff error whilst creating headReader from file %s in commit %s in %s: %v", diffFile.Name, headCommit.ID.String(), ctx.Repo.Repository.Name, err) - return CsvDiffResult{nil, "unable to load file from head commit"} + if err == errTooLarge { + return CsvDiffResult{nil, err.Error()} + } + log.Error("error whilst creating csv.Reader from file %s in head commit %s in %s: %v", diffFile.Name, headBlob.ID.String(), ctx.Repo.Repository.Name, err) + return CsvDiffResult{nil, "unable to load file"} } sections, err := gitdiff.CreateCsvDiff(diffFile, baseReader, headReader) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 35b8b3956da74..06bc79e97a6b8 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -153,7 +153,7 @@ {{if $isImage}} {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} {{else}} - {{template "repo/diff/csv_diff" dict "file" . "root" $}} + {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} {{end}}
diff --git a/templates/repo/diff/csv_diff.tmpl b/templates/repo/diff/csv_diff.tmpl index a92ef79301c6e..0f46da306e73f 100644 --- a/templates/repo/diff/csv_diff.tmpl +++ b/templates/repo/diff/csv_diff.tmpl @@ -1,6 +1,6 @@ - {{$result := call .root.CreateCsvDiff .file .root.BaseCommit .root.HeadCommit}} + {{$result := call .root.CreateCsvDiff .file .blobBase .blobHead}} {{if $result.Error}}
{{$result.Error}}
{{else if $result.Sections}} From 34f736ca04e5cf329d5ba8c562c2ccad3b33d2a6 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 17 Sep 2022 19:54:03 +0800 Subject: [PATCH 4/7] Fix reaction of issues (#21185) Fix #20860. `CommentID` in `FindReactionsOptions` should be -1 to search reactions with zero comment id. https://github.com/go-gitea/gitea/blob/8351172b6e5221290dc5b2c81e159e2eec0b43c8/models/issues/reaction.go#L108-L121 Co-authored-by: Lauris BH --- models/issues/reaction.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/models/issues/reaction.go b/models/issues/reaction.go index 87d6ff431054a..e7295c8af8190 100644 --- a/models/issues/reaction.go +++ b/models/issues/reaction.go @@ -181,6 +181,10 @@ func createReaction(ctx context.Context, opts *ReactionOptions) (*Reaction, erro Reaction: opts.Type, UserID: opts.DoerID, } + if findOpts.CommentID == 0 { + // explicit search of Issue Reactions where CommentID = 0 + findOpts.CommentID = -1 + } existingR, _, err := FindReactions(ctx, findOpts) if err != nil { @@ -256,16 +260,23 @@ func DeleteReaction(ctx context.Context, opts *ReactionOptions) error { CommentID: opts.CommentID, } - _, err := db.GetEngine(ctx).Where("original_author_id = 0").Delete(reaction) + sess := db.GetEngine(ctx).Where("original_author_id = 0") + if opts.CommentID == -1 { + reaction.CommentID = 0 + sess.MustCols("comment_id") + } + + _, err := sess.Delete(reaction) return err } // DeleteIssueReaction deletes a reaction on issue. func DeleteIssueReaction(doerID, issueID int64, content string) error { return DeleteReaction(db.DefaultContext, &ReactionOptions{ - Type: content, - DoerID: doerID, - IssueID: issueID, + Type: content, + DoerID: doerID, + IssueID: issueID, + CommentID: -1, }) } From 321964155a605900bad1c3c97163bf33b4ae5d65 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 18 Sep 2022 09:31:20 +0800 Subject: [PATCH 5/7] Treat git object mode 40755 as directory (#21195) Git uses 040000 for tree object, but some users may get 040755 for unknown reasons Try to fix #21190 * #21190 --- modules/git/parse_nogogit.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/parse_nogogit.go b/modules/git/parse_nogogit.go index 6dc4900992867..c8f0f994fc3a6 100644 --- a/modules/git/parse_nogogit.go +++ b/modules/git/parse_nogogit.go @@ -44,7 +44,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { case "160000": entry.entryMode = EntryModeCommit pos += 14 // skip over "160000 object " - case "040000": + case "040000", "040755": // git uses 040000 for tree object, but some users may get 040755 for unknown reasons entry.entryMode = EntryModeTree pos += 12 // skip over "040000 tree " default: @@ -119,7 +119,7 @@ loop: entry.entryMode = EntryModeSymlink case "160000": entry.entryMode = EntryModeCommit - case "40000": + case "40000", "40755": // git uses 40000 for tree object, but some users may get 40755 for unknown reasons entry.entryMode = EntryModeTree default: log.Debug("Unknown mode: %v", string(mode)) From 395f65c65a4b3d2bb06056b9bba3f4c016ab03e9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 18 Sep 2022 10:35:24 +0800 Subject: [PATCH 6/7] Remove unnecessary length check for repo's Description & Website (#21194) Follows #21119 The manual length check doesn't make sense nowadays: 1. The length check is already done by form's `binding:MaxSize` (then the manual check is unnecessary) 2. The CreateRepository doesn't have such check (then the manual check is inconsistent) So this PR removes these manual length checks. --- modules/repository/create.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/repository/create.go b/modules/repository/create.go index 7a25323def921..966a6a2f211ed 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -10,7 +10,6 @@ import ( "os" "path" "strings" - "unicode/utf8" "code.gitea.io/gitea/models" activities_model "code.gitea.io/gitea/models/activities" @@ -337,13 +336,6 @@ func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibilityChanged bool) (err error) { repo.LowerName = strings.ToLower(repo.Name) - if utf8.RuneCountInString(repo.Description) > 255 { - repo.Description = string([]rune(repo.Description)[:255]) - } - if utf8.RuneCountInString(repo.Website) > 255 { - repo.Website = string([]rune(repo.Website)[:255]) - } - e := db.GetEngine(ctx) if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil { From c87e6a89da05bcf57cc0b60359915efd008f744f Mon Sep 17 00:00:00 2001 From: naoki kuroda <68233204+nnnkkk7@users.noreply.github.com> Date: Sun, 18 Sep 2022 17:13:34 +0900 Subject: [PATCH 7/7] Fix typo (#21201) I fixed typo. --- cmd/serv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/serv.go b/cmd/serv.go index b00c3962f41fb..06561f348a43e 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -43,7 +43,7 @@ const ( var CmdServ = cli.Command{ Name: "serv", Usage: "This command should only be called by SSH shell", - Description: `Serv provide access auth for repositories`, + Description: "Serv provides access auth for repositories", Action: runServ, Flags: []cli.Flag{ cli.BoolFlag{