Skip to content

Commit 83550d1

Browse files
Trim to 255 runes instead of bytes
Prevents invalid UTF-8 encoding for Description and Website. Refs #7905
1 parent 15d3aa7 commit 83550d1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

models/repo.go

+5-4
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)