Merge pull request #372 from andmarios/dev

Remove newline characters from ssh key before processing it.
release/v1.15
无闻 2014-08-25 19:13:58 -07:00
commit ce55807542
1 changed files with 7 additions and 2 deletions

View File

@ -5,6 +5,8 @@
package user package user
import ( import (
"strings"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
@ -171,7 +173,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
cleanContent := strings.Replace(form.Content, "\n", "", -1)
if ok, err := models.CheckPublicKeyString(cleanContent); !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 +185,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: cleanContent,
} }
if err := models.AddPublicKey(k); err != nil { if err := models.AddPublicKey(k); err != nil {
if err == models.ErrKeyAlreadyExist { if err == models.ErrKeyAlreadyExist {