mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
* #3480 Fix new ssh key adding issues Added regular exp match (108) and remove training new line (111) that cause system to think its an ssh2 key. * #3480 Fix new ssh key adding issues -Sanitizate new lines (windows format) in posted key -Edit sanitization implementation to use string replace for code readability and maintenability.
This commit is contained in:
parent
952e510dfa
commit
e5972bbcde
@ -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).
|
// parseKeyString parses any key string in OpenSSH or SSH2 format to clean OpenSSH string (RFC4253).
|
||||||
func parseKeyString(content string) (string, error) {
|
func parseKeyString(content string) (string, error) {
|
||||||
// Transform all legal line endings to a single "\n".
|
// Transform all legal line endings to a single "\n"
|
||||||
content = strings.NewReplacer("\r\n", "\n", "\r", "\n").Replace(content)
|
|
||||||
|
// 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")
|
lines := strings.Split(content, "\n")
|
||||||
|
|
||||||
var keyType, keyContent, keyComment string
|
var keyType, keyContent, keyComment string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user