Skip to content

Commit d16e328

Browse files
committed
fix
1 parent f019480 commit d16e328

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

models/issues/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullReque
920920
var data string
921921
for _, file := range files {
922922
if blob, err := commit.GetBlobByPath(file); err == nil {
923-
data, err = blob.GetBlobContent()
923+
data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
924924
if err == nil {
925925
break
926926
}

modules/git/blob.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/base64"
1010
"io"
1111

12-
"code.gitea.io/gitea/modules/setting"
1312
"code.gitea.io/gitea/modules/typesniffer"
1413
"code.gitea.io/gitea/modules/util"
1514
)
@@ -21,15 +20,17 @@ func (b *Blob) Name() string {
2120
return b.name
2221
}
2322

24-
// GetBlobContent Gets the content of the blob as raw text
25-
// The max content size depends on MAX_DISPLAY_FILE_SIZE in app.ini
26-
func (b *Blob) GetBlobContent() (string, error) {
23+
// GetBlobContent Gets the limited content of the blob as raw text
24+
func (b *Blob) GetBlobContent(limit int64) (string, error) {
25+
if limit <= 0 {
26+
return "", nil
27+
}
2728
dataRc, err := b.DataAsync()
2829
if err != nil {
2930
return "", err
3031
}
3132
defer dataRc.Close()
32-
buf := make([]byte, setting.UI.MaxDisplayFileSize)
33+
buf := make([]byte, limit)
3334
n, _ := util.ReadAtMost(dataRc, buf)
3435
buf = buf[:n]
3536
return string(buf), nil

routers/web/repo/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
363363
ctx.Data["FileError"] = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", workFlowErr.Error())
364364
}
365365
} else if util.SliceContains([]string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}, ctx.Repo.TreePath) {
366-
if data, err := blob.GetBlobContent(); err == nil {
366+
if data, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize); err == nil {
367367
_, warnings := issue_model.GetCodeOwnersFromContent(ctx, data)
368368
if len(warnings) > 0 {
369369
ctx.Data["FileWarning"] = strings.Join(warnings, "\n")

routers/web/user/profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func Profile(ctx *context.Context) {
107107
}
108108
blob, err := commit.GetBlobByPath("README.md")
109109
if err == nil {
110-
bytes, err := blob.GetBlobContent()
110+
bytes, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
111111
if err != nil {
112112
ctx.ServerError("GetBlobContent", err)
113113
return

services/repository/files/content.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
203203
} else if entry.IsLink() {
204204
contentsResponse.Type = string(ContentTypeLink)
205205
// The target of a symlink file is the content of the file
206-
targetFromContent, err := entry.Blob().GetBlobContent()
206+
targetFromContent, err := entry.Blob().GetBlobContent(setting.UI.MaxDisplayFileSize)
207207
if err != nil {
208208
return nil, err
209209
}

tests/integration/api_packages_cargo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
8888
blob, err := commit.GetBlobByPath(path)
8989
assert.NoError(t, err)
9090

91-
content, err := blob.GetBlobContent()
91+
content, err := blob.GetBlobContent(1024)
9292
assert.NoError(t, err)
9393

9494
return content

0 commit comments

Comments
 (0)