summaryrefslogtreecommitdiff
path: root/internal/validate
diff options
context:
space:
mode:
Diffstat (limited to 'internal/validate')
-rw-r--r--internal/validate/formvalidation.go30
-rw-r--r--internal/validate/formvalidation_test.go6
2 files changed, 22 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
diff --git a/internal/validate/formvalidation_test.go b/internal/validate/formvalidation_test.go
index ff40b1dfb..f52b7402f 100644
--- a/internal/validate/formvalidation_test.go
+++ b/internal/validate/formvalidation_test.go
@@ -233,6 +233,7 @@ func (suite *ValidationTestSuite) TestValidateReason() {
badReason := "because"
goodReason := "to smash the state and destroy capitalism ultimately and completely"
tooLong := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris auctor mollis viverra. Maecenas maximus mollis sem, nec fermentum velit consectetur non. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Quisque a enim nibh. Vestibulum bibendum leo ac porttitor auctor. Curabitur velit tellus, facilisis vitae lorem a, ullamcorper efficitur leo. Sed a auctor tortor. Sed ut finibus ante, sit amet laoreet sapien. Donec ullamcorper tellus a nibh sodales vulputate. Donec id dolor eu odio mollis bibendum. Pellentesque habitant morbi tristique senectus et netus at."
+ unicode := "⎾⎿⏀⏁⏂⏃⏄⏅⏆⏇"
var err error
// check with no reason required
@@ -256,6 +257,11 @@ func (suite *ValidationTestSuite) TestValidateReason() {
assert.Equal(suite.T(), nil, err)
}
+ err = validate.SignUpReason(unicode, false)
+ if assert.NoError(suite.T(), err) {
+ assert.Equal(suite.T(), nil, err)
+ }
+
// check with reason required
err = validate.SignUpReason(empty, true)
if assert.Error(suite.T(), err) {