summaryrefslogtreecommitdiff
path: root/internal/validate/formvalidation.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-11-03 14:38:06 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-03 14:38:06 +0100
commitbd05040133ec5ce5b431e05d8c873195d9501d6d (patch)
treec1c7a248b31dccf9e768d43efacc14f7f93d553f /internal/validate/formvalidation.go
parent[feature] Allow user to show instead of landing page on / (#922) (diff)
downloadgotosocial-bd05040133ec5ce5b431e05d8c873195d9501d6d.tar.xz
[bugfix] Use []rune to check length of user-submitted text (#948)
Diffstat (limited to 'internal/validate/formvalidation.go')
-rw-r--r--internal/validate/formvalidation.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/internal/validate/formvalidation.go b/internal/validate/formvalidation.go
index c51c17922..ccf5e6504 100644
--- a/internal/validate/formvalidation.go
+++ b/internal/validate/formvalidation.go
@@ -50,7 +50,7 @@ func NewPassword(password string) error {
return errors.New("no password provided")
}
- if len(password) > maximumPasswordLength {
+ if len([]rune(password)) > maximumPasswordLength {
return fmt.Errorf("password should be no more than %d chars", maximumPasswordLength)
}
@@ -113,12 +113,14 @@ func SignUpReason(reason string, reasonRequired bool) error {
return errors.New("no reason provided")
}
- if len(reason) < minimumReasonLength {
- return fmt.Errorf("reason should be at least %d chars but '%s' was %d", minimumReasonLength, reason, len(reason))
+ length := len([]rune(reason))
+
+ if length < minimumReasonLength {
+ return fmt.Errorf("reason should be at least %d chars but '%s' was %d", minimumReasonLength, reason, length)
}
- if len(reason) > maximumReasonLength {
- return fmt.Errorf("reason should be no more than %d chars but given reason was %d", maximumReasonLength, len(reason))
+ if length > maximumReasonLength {
+ return fmt.Errorf("reason should be no more than %d chars but given reason was %d", maximumReasonLength, length)
}
return nil
}
@@ -164,7 +166,7 @@ func CustomCSS(customCSS string) error {
return errors.New("accounts-allow-custom-css is not enabled for this instance")
}
- if length := len(customCSS); length > maximumCustomCSSLength {
+ if length := len([]rune(customCSS)); length > maximumCustomCSSLength {
return fmt.Errorf("custom_css must be less than %d characters, but submitted custom_css was %d characters", maximumCustomCSSLength, length)
}
return nil
@@ -182,8 +184,8 @@ func EmojiShortcode(shortcode string) error {
// SiteTitle ensures that the given site title is within spec.
func SiteTitle(siteTitle string) error {
- if len(siteTitle) > maximumSiteTitleLength {
- return fmt.Errorf("site title should be no more than %d chars but given title was %d", maximumSiteTitleLength, len(siteTitle))
+ if length := len([]rune(siteTitle)); length > maximumSiteTitleLength {
+ return fmt.Errorf("site title should be no more than %d chars but given title was %d", maximumSiteTitleLength, length)
}
return nil
@@ -191,8 +193,8 @@ func SiteTitle(siteTitle string) error {
// SiteShortDescription ensures that the given site short description is within spec.
func SiteShortDescription(d string) error {
- if len(d) > maximumShortDescriptionLength {
- return fmt.Errorf("short description should be no more than %d chars but given description was %d", maximumShortDescriptionLength, len(d))
+ if length := len([]rune(d)); length > maximumShortDescriptionLength {
+ return fmt.Errorf("short description should be no more than %d chars but given description was %d", maximumShortDescriptionLength, length)
}
return nil
@@ -200,8 +202,8 @@ func SiteShortDescription(d string) error {
// SiteDescription ensures that the given site description is within spec.
func SiteDescription(d string) error {
- if len(d) > maximumDescriptionLength {
- return fmt.Errorf("description should be no more than %d chars but given description was %d", maximumDescriptionLength, len(d))
+ if length := len([]rune(d)); length > maximumDescriptionLength {
+ return fmt.Errorf("description should be no more than %d chars but given description was %d", maximumDescriptionLength, length)
}
return nil
@@ -209,8 +211,8 @@ func SiteDescription(d string) error {
// SiteTerms ensures that the given site terms string is within spec.
func SiteTerms(t string) error {
- if len(t) > maximumSiteTermsLength {
- return fmt.Errorf("terms should be no more than %d chars but given terms was %d", maximumSiteTermsLength, len(t))
+ if length := len([]rune(t)); length > maximumSiteTermsLength {
+ return fmt.Errorf("terms should be no more than %d chars but given terms was %d", maximumSiteTermsLength, length)
}
return nil