mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 05:12:25 -05:00
[bugfix] Use []rune to check length of user-submitted text (#948)
This commit is contained in:
parent
f3fc040c2e
commit
bd05040133
6 changed files with 40 additions and 32 deletions
|
|
@ -163,8 +163,8 @@ func validateCreateMedia(form *model.AttachmentRequest) error {
|
|||
return fmt.Errorf("file size limit exceeded: limit is %d bytes but attachment was %d bytes", maxSize, form.File.Size)
|
||||
}
|
||||
|
||||
if len(form.Description) > maxDescriptionChars {
|
||||
return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", minDescriptionChars, maxDescriptionChars, len(form.Description))
|
||||
if length := len([]rune(form.Description)); length > maxDescriptionChars {
|
||||
return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", minDescriptionChars, maxDescriptionChars, length)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ func validateUpdateMedia(form *model.AttachmentUpdateRequest) error {
|
|||
maxDescriptionChars := config.GetMediaDescriptionMaxChars()
|
||||
|
||||
if form.Description != nil {
|
||||
if len(*form.Description) < minDescriptionChars || len(*form.Description) > maxDescriptionChars {
|
||||
return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", minDescriptionChars, maxDescriptionChars, len(*form.Description))
|
||||
if length := len([]rune(*form.Description)); length < minDescriptionChars || length > maxDescriptionChars {
|
||||
return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", minDescriptionChars, maxDescriptionChars, length)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue