From 0f812746b7fd9dfeef41e329af5215772672689a Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Mon, 7 Aug 2023 01:25:54 -0700 Subject: [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 --- internal/api/client/accounts/accountcreate.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'internal/api/client/accounts') 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()) } -- cgit v1.2.3