Skip to content

Commit 30399cf

Browse files
juergenhoetzeltechknowlogickzeripathlafriks
authored
Trim to 255 runes instead of bytes (#12150)
* Trim to 255 runes instead of bytes Prevents invalid UTF-8 encoding for Description and Website. Refs #7905 * Apply suggestions from code review Co-authored-by: zeripath <[email protected]> Co-authored-by: techknowlogick <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 12f9dd8 commit 30399cf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

models/repo.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"fmt"
1313
"html/template"
14+
"unicode/utf8"
1415

1516
// Needed for jpeg support
1617
_ "image/jpeg"
@@ -1394,11 +1395,11 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
13941395
func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
13951396
repo.LowerName = strings.ToLower(repo.Name)
13961397

1397-
if len(repo.Description) > 255 {
1398-
repo.Description = repo.Description[:255]
1398+
if utf8.RuneCountInString(repo.Description) > 255 {
1399+
repo.Description = string([]rune(repo.Description)[:255])
13991400
}
1400-
if len(repo.Website) > 255 {
1401-
repo.Website = repo.Website[:255]
1401+
if utf8.RuneCountInString(repo.Website) > 255 {
1402+
repo.Website = string([]rune(repo.Website)[:255])
14021403
}
14031404

14041405
if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {

0 commit comments

Comments
 (0)