aboutsummaryrefslogtreecommitdiffstats
path: root/routers/user/setting.go
diff options
context:
space:
mode:
authorMarios Andreopoulos <opensource@andmarios.com>2014-08-25 18:54:50 +0300
committerMarios Andreopoulos <opensource@andmarios.com>2014-08-25 18:54:50 +0300
commit12639c577f297687539283bf8877a5583ecb8447 (patch)
treee0580d4fcb35dc0f6e8d51931586b785f780b776 /routers/user/setting.go
parentf2c263c54facdcbc9375a47535c0389fd7d05875 (diff)
downloadgitea-12639c577f297687539283bf8877a5583ecb8447.tar.gz
gitea-12639c577f297687539283bf8877a5583ecb8447.zip
Remove newline characters from ssh key before processing it.
Fixes issue #370: https://github.com/gogits/gogs/issues/370
Diffstat (limited to 'routers/user/setting.go')
-rw-r--r--routers/user/setting.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/routers/user/setting.go b/routers/user/setting.go
index e091bc4381..21ff6df7c9 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -171,7 +171,10 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
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.Redirect("/user/settings/ssh")
return
@@ -180,7 +183,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
k := &models.PublicKey{
OwnerId: ctx.User.Id,
Name: form.SSHTitle,
- Content: form.Content,
+ Content: cleanKeyContent,
}
if err := models.AddPublicKey(k); err != nil {
if err == models.ErrKeyAlreadyExist {