From d686aa0d31e039bc409d5bee385c27c7fbb2c47f Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 15 Jun 2023 10:39:34 +0900 Subject: Fix profile render when the README.md size is larger than 1024 bytes (#25270) Backport #25131 --- modules/git/blob.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'modules/git') 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 -- cgit v1.2.3