diff options
author | 无闻 <joe2010xtmf@163.com> | 2014-08-25 19:13:58 -0700 |
---|---|---|
committer | 无闻 <joe2010xtmf@163.com> | 2014-08-25 19:13:58 -0700 |
commit | ce55807542523e9fef4ab9ab95a1aab116eafcbf (patch) | |
tree | c36c81a63b70912bced8477c8a72fb741be5270b | |
parent | f2c263c54facdcbc9375a47535c0389fd7d05875 (diff) | |
parent | 510d5a5d74301ad0083b1ea10aef6caa17cde8d8 (diff) |
Merge pull request #372 from andmarios/dev
Remove newline characters from ssh key before processing it.
-rw-r--r-- | routers/user/setting.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/routers/user/setting.go b/routers/user/setting.go index e091bc43..d3b79213 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -5,6 +5,8 @@ package user import ( + "strings" + "github.com/Unknwon/com" "github.com/gogits/gogs/models" @@ -171,7 +173,10 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { 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.Redirect("/user/settings/ssh") return @@ -180,7 +185,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { k := &models.PublicKey{ OwnerId: ctx.User.Id, Name: form.SSHTitle, - Content: form.Content, + Content: cleanContent, } if err := models.AddPublicKey(k); err != nil { if err == models.ErrKeyAlreadyExist { |