summaryrefslogtreecommitdiff
path: root/internal/validate/formvalidation.go
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2023-08-07 01:25:54 -0700
committerLibravatar GitHub <noreply@github.com>2023-08-07 10:25:54 +0200
commit0f812746b7fd9dfeef41e329af5215772672689a (patch)
treeadfc0c9e4412982224d32019b8abfc2895cd3f66 /internal/validate/formvalidation.go
parent[chore]: Bump golang.org/x/oauth2 from 0.10.0 to 0.11.0 (#2076) (diff)
downloadgotosocial-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/validate/formvalidation.go')
-rw-r--r--internal/validate/formvalidation.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/internal/validate/formvalidation.go b/internal/validate/formvalidation.go
index 76ce6a8de..1b5996b4b 100644
--- a/internal/validate/formvalidation.go
+++ b/internal/validate/formvalidation.go
@@ -99,14 +99,19 @@ func Email(email string) error {
return err
}
-// Language checks that the given language string is a 2- or 3-letter ISO 639 code.
-// Returns an error if the language cannot be parsed. See: https://pkg.go.dev/golang.org/x/text/language
-func Language(lang string) error {
+// Language checks that the given language string is a valid, if not necessarily canonical, BCP 47 language tag.
+// Returns a canonicalized version of the tag if the language can be parsed.
+// Returns an error if the language cannot be parsed.
+// See: https://pkg.go.dev/golang.org/x/text/language
+func Language(lang string) (string, error) {
if lang == "" {
- return errors.New("no language provided")
+ return "", errors.New("no language provided")
}
- _, err := language.ParseBase(lang)
- return err
+ parsed, err := language.Parse(lang)
+ if err != nil {
+ return "", err
+ }
+ return parsed.String(), err
}
// SignUpReason checks that a sufficient reason is given for a server signup request