From 3a3782bb7fed768c1e832ff4c0a77f2f5281ed05 Mon Sep 17 00:00:00 2001 From: stroucki Date: Wed, 23 Nov 2016 19:52:55 -0500 Subject: [PATCH] Handle ssh key import better (#224) * Handle user ssh key input better ssh_key: when user submitted keys had a newline at the end, strings.Split would have created a slice with an empty last element, and the key type check would be incorrect. Perhaps a better way is to look for 'ssh-rsa' or 'ssh-dsa' at the beginning of the string, but this is simple. * ssh_key: correct indentation --- models/ssh_key.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/ssh_key.go b/models/ssh_key.go index 4a6acb8ecf..98fb2dcdbf 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -105,6 +105,8 @@ func extractTypeFromBase64Key(key string) (string, error) { func parseKeyString(content string) (string, error) { // Transform all legal line endings to a single "\n". content = strings.NewReplacer("\r\n", "\n", "\r", "\n").Replace(content) + // remove trailing newline (and beginning spaces too) + content = strings.TrimSpace(content) lines := strings.Split(content, "\n") var keyType, keyContent, keyComment string