diff options
author | yp05327 <576951401@qq.com> | 2023-06-15 10:39:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-15 01:39:34 +0000 |
commit | d686aa0d31e039bc409d5bee385c27c7fbb2c47f (patch) | |
tree | 33d062a93fe19b8f328c051e2994b38116337d59 /modules/git | |
parent | 037366f93f94a3185b56d21e90335305c8d4b685 (diff) | |
download | gitea-d686aa0d31e039bc409d5bee385c27c7fbb2c47f.tar.gz gitea-d686aa0d31e039bc409d5bee385c27c7fbb2c47f.zip |
Fix profile render when the README.md size is larger than 1024 bytes (#25270)
Backport #25131
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/blob.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/modules/git/blob.go b/modules/git/blob.go index 8864f54d1b..bcecb42e16 100644 --- a/modules/git/blob.go +++ b/modules/git/blob.go @@ -20,17 +20,18 @@ func (b *Blob) Name() string { return b.name } -// GetBlobContent Gets the content of the blob as raw text -func (b *Blob) GetBlobContent() (string, error) { +// GetBlobContent Gets the limited content of the blob as raw text +func (b *Blob) GetBlobContent(limit int64) (string, error) { + if limit <= 0 { + return "", nil + } dataRc, err := b.DataAsync() if err != nil { return "", err } defer dataRc.Close() - buf := make([]byte, 1024) - n, _ := util.ReadAtMost(dataRc, buf) - buf = buf[:n] - return string(buf), nil + buf, err := util.ReadWithLimit(dataRc, int(limit)) + return string(buf), err } // GetBlobLineCount gets line count of the blob |