Skip to content

Commit a680c91

Browse files
juergenhoetzeltechknowlogickzeripathlafriks
committed
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 <art27@cantab.net> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
1 parent d9c18cb commit a680c91

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"
@@ -1384,11 +1385,11 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
13841385
func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
13851386
repo.LowerName = strings.ToLower(repo.Name)
13861387

1387-
if len(repo.Description) > 255 {
1388-
repo.Description = repo.Description[:255]
1388+
if utf8.RuneCountInString(repo.Description) > 255 {
1389+
repo.Description = string([]rune(repo.Description)[:255])
13891390
}
1390-
if len(repo.Website) > 255 {
1391-
repo.Website = repo.Website[:255]
1391+
if utf8.RuneCountInString(repo.Website) > 255 {
1392+
repo.Website = string([]rune(repo.Website)[:255])
13921393
}
13931394

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

0 commit comments

Comments
 (0)