1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-17 23:54:25 +00:00

Remove newline characters from ssh key before processing it.

Fixes issue #370: https://github.com/gogits/gogs/issues/370
This commit is contained in:
Marios Andreopoulos 2014-08-25 18:54:50 +03:00
parent f2c263c54f
commit 12639c577f

View File

@ -171,7 +171,10 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
return return
} }
if ok, err := models.CheckPublicKeyString(form.Content); !ok { // Remove newline characters from form.KeyContent
cleanKeyContent := strings.Replace(form.KeyContent, "\n", "", -1),
if ok, err := models.CheckPublicKeyString(cleanKeyContent); !ok {
ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error()))
ctx.Redirect("/user/settings/ssh") ctx.Redirect("/user/settings/ssh")
return return
@ -180,7 +183,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
k := &models.PublicKey{ k := &models.PublicKey{
OwnerId: ctx.User.Id, OwnerId: ctx.User.Id,
Name: form.SSHTitle, Name: form.SSHTitle,
Content: form.Content, Content: cleanKeyContent,
} }
if err := models.AddPublicKey(k); err != nil { if err := models.AddPublicKey(k); err != nil {
if err == models.ErrKeyAlreadyExist { if err == models.ErrKeyAlreadyExist {