Skip to content

Commit 3a3782b

Browse files
strouckilunny
authored andcommitted
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
1 parent cb16028 commit 3a3782b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

models/ssh_key.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func extractTypeFromBase64Key(key string) (string, error) {
105105
func parseKeyString(content string) (string, error) {
106106
// Transform all legal line endings to a single "\n".
107107
content = strings.NewReplacer("\r\n", "\n", "\r", "\n").Replace(content)
108+
// remove trailing newline (and beginning spaces too)
109+
content = strings.TrimSpace(content)
108110
lines := strings.Split(content, "\n")
109111

110112
var keyType, keyContent, keyComment string

0 commit comments

Comments
 (0)