diff options
author | Jürgen Hötzel <juergen@hoetzel.info> | 2020-07-07 23:35:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-08 00:35:52 +0300 |
commit | 30399cf04ad7578c67d4268878df071cac515fc9 (patch) | |
tree | cbc06f40eddff0528ecb6d4c38ab779c5ac968d7 /models | |
parent | 12f9dd8fa9c02be1c38f7994066c986e50dfd2e9 (diff) | |
download | gitea-30399cf04ad7578c67d4268878df071cac515fc9.tar.gz gitea-30399cf04ad7578c67d4268878df071cac515fc9.zip |
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>
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/models/repo.go b/models/repo.go index 5c6aae9557..a191571b8a 100644 --- a/models/repo.go +++ b/models/repo.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "html/template" + "unicode/utf8" // Needed for jpeg support _ "image/jpeg" @@ -1394,11 +1395,11 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) { func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) { repo.LowerName = strings.ToLower(repo.Name) - if len(repo.Description) > 255 { - repo.Description = repo.Description[:255] + if utf8.RuneCountInString(repo.Description) > 255 { + repo.Description = string([]rune(repo.Description)[:255]) } - if len(repo.Website) > 255 { - repo.Website = repo.Website[:255] + if utf8.RuneCountInString(repo.Website) > 255 { + repo.Website = string([]rune(repo.Website)[:255]) } if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil { |