aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/ssh_key.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go
index 0925b9ba..e2c3431d 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -104,8 +104,18 @@ func extractTypeFromBase64Key(key string) (string, error) {
// parseKeyString parses any key string in OpenSSH or SSH2 format to clean OpenSSH string (RFC4253).
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)
+ // Transform all legal line endings to a single "\n"
+
+ // Replace all windows full new lines ("\r\n")
+ content = strings.Replace(content, "\r\n", "\n", -1)
+
+ // Replace all windows half new lines ("\r"), if it happen not to match replace above
+ content = strings.Replace(content, "\r", "\n", -1)
+
+ // Replace ending new line as its may cause unwanted behaviour (extra line means not a single line key | OpenSSH key)
+ content = strings.TrimRight(content, "\n")
+
+ // split lines
lines := strings.Split(content, "\n")
var keyType, keyContent, keyComment string