Skip to content

Commit 5539b7f

Browse files
committed
Validate language
1 parent 60ff73a commit 5539b7f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ website = Website
440440
location = Location
441441
update_theme = Update Theme
442442
update_profile = Update Profile
443+
update_language_not_found = Language '%s' is not available.
443444
update_profile_success = Your profile has been updated.
444445
change_username = Your username has been changed.
445446
change_username_prompt = Note: username changes also change your account URL.

routers/user/setting/profile.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"code.gitea.io/gitea/modules/context"
2020
"code.gitea.io/gitea/modules/log"
2121
"code.gitea.io/gitea/modules/setting"
22+
"code.gitea.io/gitea/modules/util"
2223

2324
"github.com/unknwon/i18n"
2425
)
@@ -94,8 +95,12 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) {
9495
ctx.User.KeepEmailPrivate = form.KeepEmailPrivate
9596
ctx.User.Website = form.Website
9697
ctx.User.Location = form.Location
97-
if len(form.Language) == 5 {
98-
// TODO: check if lang code is valide
98+
if len(form.Language) != 0 {
99+
if !util.IsStringInSlice(form.Language, setting.Langs) {
100+
ctx.Flash.Error(ctx.Tr("settings.update_language_not_found", form.Language))
101+
ctx.Redirect(setting.AppSubURL + "/user/settings")
102+
return
103+
}
99104
ctx.User.Language = form.Language
100105
}
101106
ctx.User.Description = form.Description

0 commit comments

Comments
 (0)