diff options
author | 2023-08-07 01:25:54 -0700 | |
---|---|---|
committer | 2023-08-07 10:25:54 +0200 | |
commit | 0f812746b7fd9dfeef41e329af5215772672689a (patch) | |
tree | adfc0c9e4412982224d32019b8abfc2895cd3f66 /internal/api/client/accounts/accountcreate.go | |
parent | [chore]: Bump golang.org/x/oauth2 from 0.10.0 to 0.11.0 (#2076) (diff) | |
download | gotosocial-0f812746b7fd9dfeef41e329af5215772672689a.tar.xz |
[feature] Allow full BCP 47 in language inputs (#2067)
* Allow full BCP 47 in language inputs
Fixes #2066
* Fuse validation and normalization for languages
* Remove outdated comment line
* Move post language canonicalization test
Diffstat (limited to 'internal/api/client/accounts/accountcreate.go')
-rw-r--r-- | internal/api/client/accounts/accountcreate.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/internal/api/client/accounts/accountcreate.go b/internal/api/client/accounts/accountcreate.go index c8247ecf2..473000f6d 100644 --- a/internal/api/client/accounts/accountcreate.go +++ b/internal/api/client/accounts/accountcreate.go @@ -87,7 +87,7 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) { return } - if err := validateCreateAccount(form); err != nil { + if err := validateNormalizeCreateAccount(form); err != nil { apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) return } @@ -110,9 +110,10 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) { c.JSON(http.StatusOK, ti) } -// validateCreateAccount checks through all the necessary prerequisites for creating a new account, +// validateNormalizeCreateAccount checks through all the necessary prerequisites for creating a new account, // according to the provided account create request. If the account isn't eligible, an error will be returned. -func validateCreateAccount(form *apimodel.AccountCreateRequest) error { +// Side effect: normalizes the provided language tag for the user's locale. +func validateNormalizeCreateAccount(form *apimodel.AccountCreateRequest) error { if form == nil { return errors.New("form was nil") } @@ -137,9 +138,11 @@ func validateCreateAccount(form *apimodel.AccountCreateRequest) error { return errors.New("agreement to terms and conditions not given") } - if err := validate.Language(form.Locale); err != nil { + locale, err := validate.Language(form.Locale) + if err != nil { return err } + form.Locale = locale return validate.SignUpReason(form.Reason, config.GetAccountsReasonRequired()) } |