diff options
author | Jürgen Hötzel <juergen@hoetzel.info> | 2020-07-07 23:35:52 +0200 |
---|---|---|
committer | Matti R <matti@mdranta.net> | 2020-07-07 19:05:35 -0400 |
commit | a680c911e4e686d0df1e401647217bce2f087cff (patch) | |
tree | 0cb216bc34bdea70ac1fbee11576b4f7f5bc2aa1 /models | |
parent | d9c18cbba01b259615ac5da851164c8e20240a23 (diff) | |
download | gitea-a680c911e4e686d0df1e401647217bce2f087cff.tar.gz gitea-a680c911e4e686d0df1e401647217bce2f087cff.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 8a5c147404..a11c54fb00 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" @@ -1384,11 +1385,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 { |