Skip to content

User Settings: Ignore empty language codes & validate #13755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integrations/privateactivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func testPrivateActivityHelperEnablePrivateActivity(t *testing.T) {
"_csrf": GetCSRF(t, session, "/user/settings"),
"name": privateActivityTestUser,
"email": privateActivityTestUser + "@example.com",
"language": "en-us",
"language": "en-US",
"keep_activity_private": "1",
})
session.MakeRequest(t, req, http.StatusFound)
Expand Down
4 changes: 2 additions & 2 deletions integrations/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRenameUsername(t *testing.T) {
"_csrf": GetCSRF(t, session, "/user/settings"),
"name": "newUsername",
"email": "[email protected]",
"language": "en-us",
"language": "en-US",
})
session.MakeRequest(t, req, http.StatusFound)

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

Expand Down
2 changes: 1 addition & 1 deletion integrations/xss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestXSSUserFullName(t *testing.T) {
"name": user.Name,
"full_name": fullName,
"email": user.Email,
"language": "en-us",
"language": "en-US",
})
session.MakeRequest(t, req, http.StatusFound)

Expand Down
2 changes: 1 addition & 1 deletion modules/auth/user_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ type UpdateProfileForm struct {
KeepEmailPrivate bool
Website string `binding:"ValidUrl;MaxSize(255)"`
Location string `binding:"MaxSize(50)"`
Language string `binding:"Size(5)"`
Language string
Description string `binding:"MaxSize(255)"`
KeepActivityPrivate bool
}
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ website = Website
location = Location
update_theme = Update Theme
update_profile = Update Profile
update_language_not_found = Language '%s' is not available.
update_profile_success = Your profile has been updated.
change_username = Your username has been changed.
change_username_prompt = Note: username changes also change your account URL.
Expand Down
10 changes: 9 additions & 1 deletion routers/user/setting/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

"github.com/unknwon/i18n"
)
Expand Down Expand Up @@ -94,7 +95,14 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) {
ctx.User.KeepEmailPrivate = form.KeepEmailPrivate
ctx.User.Website = form.Website
ctx.User.Location = form.Location
ctx.User.Language = form.Language
if len(form.Language) != 0 {
if !util.IsStringInSlice(form.Language, setting.Langs) {
ctx.Flash.Error(ctx.Tr("settings.update_language_not_found", form.Language))
ctx.Redirect(setting.AppSubURL + "/user/settings")
return
}
ctx.User.Language = form.Language
}
ctx.User.Description = form.Description
ctx.User.KeepActivityPrivate = form.KeepActivityPrivate
if err := models.UpdateUserSetting(ctx.User); err != nil {
Expand Down