Skip to content

Commit e599f3c

Browse files
6543ashimokawa
authored andcommitted
User Settings: Ignore empty language codes & validate (go-gitea#13755)
1 parent 7ec38e6 commit e599f3c

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

integrations/privateactivity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func testPrivateActivityHelperEnablePrivateActivity(t *testing.T) {
4545
"_csrf": GetCSRF(t, session, "/user/settings"),
4646
"name": privateActivityTestUser,
4747
"email": privateActivityTestUser + "@example.com",
48-
"language": "en-us",
48+
"language": "en-US",
4949
"keep_activity_private": "1",
5050
})
5151
session.MakeRequest(t, req, http.StatusFound)

integrations/user_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestRenameUsername(t *testing.T) {
3030
"_csrf": GetCSRF(t, session, "/user/settings"),
3131
"name": "newUsername",
3232
"email": "[email protected]",
33-
"language": "en-us",
33+
"language": "en-US",
3434
})
3535
session.MakeRequest(t, req, http.StatusFound)
3636

@@ -100,7 +100,7 @@ func TestRenameReservedUsername(t *testing.T) {
100100
"_csrf": GetCSRF(t, session, "/user/settings"),
101101
"name": reservedUsername,
102102
"email": "[email protected]",
103-
"language": "en-us",
103+
"language": "en-US",
104104
})
105105
resp := session.MakeRequest(t, req, http.StatusFound)
106106

integrations/xss_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestXSSUserFullName(t *testing.T) {
2424
"name": user.Name,
2525
"full_name": fullName,
2626
"email": user.Email,
27-
"language": "en-us",
27+
"language": "en-US",
2828
})
2929
session.MakeRequest(t, req, http.StatusFound)
3030

modules/auth/user_form.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ type UpdateProfileForm struct {
202202
KeepEmailPrivate bool
203203
Website string `binding:"ValidUrl;MaxSize(255)"`
204204
Location string `binding:"MaxSize(50)"`
205-
Language string `binding:"Size(5)"`
205+
Language string
206206
Description string `binding:"MaxSize(255)"`
207207
KeepActivityPrivate bool
208208
}

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: 9 additions & 1 deletion
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,7 +95,14 @@ 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-
ctx.User.Language = form.Language
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+
}
104+
ctx.User.Language = form.Language
105+
}
98106
ctx.User.Description = form.Description
99107
ctx.User.KeepActivityPrivate = form.KeepActivityPrivate
100108
if err := models.UpdateUserSetting(ctx.User); err != nil {

0 commit comments

Comments
 (0)