]> source.dussan.org Git - gitea.git/commitdiff
Remove newline characters from ssh key before processing it.
authorMarios Andreopoulos <opensource@andmarios.com>
Mon, 25 Aug 2014 15:54:50 +0000 (18:54 +0300)
committerMarios Andreopoulos <opensource@andmarios.com>
Mon, 25 Aug 2014 15:54:50 +0000 (18:54 +0300)
Fixes issue #370: https://github.com/gogits/gogs/issues/370

routers/user/setting.go

index e091bc43815d41fd351ff8c326d622827863ed84..21ff6df7c9c2a11480df00d9b1b5a17a9cef8782 100644 (file)
@@ -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 {