-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix profile render when the README.md size is larger than 1024 bytes #25131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7e84b56
fix
yp05327 71d8475
improve
yp05327 d5af147
remove code
yp05327 110196b
add 1024 limit for old use
yp05327 888cb8b
fix lint
yp05327 3afc0d2
depends on MAX_DISPLAY_FILE_SIZE
yp05327 d661b2c
Merge branch 'main' into fix-profile-render
GiteaBot f019480
Merge branch 'main' into fix-profile-render
GiteaBot d16e328
fix
yp05327 72c8f83
Update services/repository/files/content.go
wxiaoguang 0e2e0d8
fix memory usage
wxiaoguang 6f749e9
Merge branch 'main' into fix-profile-render
GiteaBot bc1f0ca
Merge branch 'main' into fix-profile-render
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package util | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type readerWithError struct { | ||
buf *bytes.Buffer | ||
} | ||
|
||
func (r *readerWithError) Read(p []byte) (n int, err error) { | ||
if r.buf.Len() < 2 { | ||
return 0, errors.New("test error") | ||
} | ||
return r.buf.Read(p) | ||
} | ||
|
||
func TestReadWithLimit(t *testing.T) { | ||
bs := []byte("0123456789abcdef") | ||
|
||
// normal test | ||
buf, err := readWithLimit(bytes.NewBuffer(bs), 5, 2) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("01"), buf) | ||
|
||
buf, err = readWithLimit(bytes.NewBuffer(bs), 5, 5) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("01234"), buf) | ||
|
||
buf, err = readWithLimit(bytes.NewBuffer(bs), 5, 6) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("012345"), buf) | ||
|
||
buf, err = readWithLimit(bytes.NewBuffer(bs), 5, len(bs)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("0123456789abcdef"), buf) | ||
|
||
buf, err = readWithLimit(bytes.NewBuffer(bs), 5, 100) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("0123456789abcdef"), buf) | ||
|
||
// test with error | ||
buf, err = readWithLimit(&readerWithError{bytes.NewBuffer(bs)}, 5, 10) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("0123456789"), buf) | ||
|
||
buf, err = readWithLimit(&readerWithError{bytes.NewBuffer(bs)}, 5, 100) | ||
assert.ErrorContains(t, err, "test error") | ||
assert.Empty(t, buf) | ||
|
||
// test public function | ||
buf, err = ReadWithLimit(bytes.NewBuffer(bs), 2) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("01"), buf) | ||
|
||
buf, err = ReadWithLimit(bytes.NewBuffer(bs), 9999999) | ||
assert.NoError(t, err) | ||
assert.Equal(t, []byte("0123456789abcdef"), buf) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should investigate closer what this does, but does not have to be in this PR. It might be that this is another undiscovered bug and it should actually use
0
here.