diff --git a/modules/auth/cloudbrain.go b/modules/auth/cloudbrain.go index 335bc1666..8325dc063 100755 --- a/modules/auth/cloudbrain.go +++ b/modules/auth/cloudbrain.go @@ -12,7 +12,7 @@ type CreateCloudBrainForm struct { Attachment string `form:"attachment" binding:"Required"` JobType string `form:"job_type" binding:"Required"` BenchmarkCategory string `form:"get_benchmark_category"` - GpuType string `form:"gpu_type"` + GpuType string `form:"gpu_type"` } type CommitImageCloudBrainForm struct { diff --git a/modules/base/tool.go b/modules/base/tool.go index 157bd9bc3..ebbff8671 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -21,6 +21,7 @@ import ( "strings" "time" "unicode" + "unicode/utf8" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -284,22 +285,22 @@ func Subtract(left interface{}, right interface{}) interface{} { // EllipsisString returns a truncated short string, // it appends '...' in the end of the length of string is too large. func EllipsisString(str string, length int) string { - if length <= 3 { + if utf8.RuneCountInString(str) <= 3 { return "..." } - if len(str) <= length { + if utf8.RuneCountInString(str) <= length { return str } - return str[:length-3] + "..." + return string([]rune(str)[:length-3]) + "..." } // TruncateString returns a truncated string with given limit, // it returns input string if length is not reached limit. func TruncateString(str string, limit int) string { - if len(str) < limit { + if utf8.RuneCountInString(str) < limit { return str } - return str[:limit] + return string([]rune(str)[:limit]) } // StringsToInt64s converts a slice of string to a slice of int64.