diff options
author | 2022-11-03 14:38:06 +0100 | |
---|---|---|
committer | 2022-11-03 14:38:06 +0100 | |
commit | bd05040133ec5ce5b431e05d8c873195d9501d6d (patch) | |
tree | c1c7a248b31dccf9e768d43efacc14f7f93d553f /internal/api/client/status/statuscreate.go | |
parent | [feature] Allow user to show instead of landing page on / (#922) (diff) | |
download | gotosocial-bd05040133ec5ce5b431e05d8c873195d9501d6d.tar.xz |
[bugfix] Use []rune to check length of user-submitted text (#948)
Diffstat (limited to 'internal/api/client/status/statuscreate.go')
-rw-r--r-- | internal/api/client/status/statuscreate.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/api/client/status/statuscreate.go b/internal/api/client/status/statuscreate.go index 13aa5d173..3b2ee1e05 100644 --- a/internal/api/client/status/statuscreate.go +++ b/internal/api/client/status/statuscreate.go @@ -124,8 +124,8 @@ func validateCreateStatus(form *model.AdvancedStatusCreateForm) error { maxCwChars := config.GetStatusesCWMaxChars() if form.Status != "" { - if len(form.Status) > maxChars { - return fmt.Errorf("status too long, %d characters provided but limit is %d", len(form.Status), maxChars) + if length := len([]rune(form.Status)); length > maxChars { + return fmt.Errorf("status too long, %d characters provided but limit is %d", length, maxChars) } } @@ -141,15 +141,15 @@ func validateCreateStatus(form *model.AdvancedStatusCreateForm) error { return fmt.Errorf("too many poll options provided, %d provided but limit is %d", len(form.Poll.Options), maxPollOptions) } for _, p := range form.Poll.Options { - if len(p) > maxPollChars { - return fmt.Errorf("poll option too long, %d characters provided but limit is %d", len(p), maxPollChars) + if length := len([]rune(p)); length > maxPollChars { + return fmt.Errorf("poll option too long, %d characters provided but limit is %d", length, maxPollChars) } } } if form.SpoilerText != "" { - if len(form.SpoilerText) > maxCwChars { - return fmt.Errorf("content-warning/spoilertext too long, %d characters provided but limit is %d", len(form.SpoilerText), maxCwChars) + if length := len([]rune(form.SpoilerText)); length > maxCwChars { + return fmt.Errorf("content-warning/spoilertext too long, %d characters provided but limit is %d", length, maxCwChars) } } |