2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-17 08:12:57 +00:00

internal: backend: sftp: support user@domain parsing as user

This commit is contained in:
streambinder 2019-09-26 12:23:31 +02:00
parent 72bd467e23
commit 97e5ce4344
2 changed files with 12 additions and 3 deletions

View File

@ -56,8 +56,11 @@ func ParseConfig(s string) (interface{}, error) {
host = data[0] host = data[0]
dir = data[1] dir = data[1]
// split user and host at the "@" // split user and host at the "@"
data = strings.SplitN(host, "@", 2) data = strings.SplitN(host, "@", 3)
if len(data) == 2 { if len(data) == 3 {
user = data[0] + "@" + data[1]
host = data[2]
} else if len(data) == 2 {
user = data[0] user = data[0]
host = data[1] host = data[1]
} }

View File

@ -1,6 +1,8 @@
package sftp package sftp
import "testing" import (
"testing"
)
var configTests = []struct { var configTests = []struct {
in string in string
@ -41,6 +43,10 @@ var configTests = []struct {
"sftp:user@host:/dir/subdir", "sftp:user@host:/dir/subdir",
Config{User: "user", Host: "host", Path: "/dir/subdir"}, Config{User: "user", Host: "host", Path: "/dir/subdir"},
}, },
{
"sftp:user@domain@host:/dir/subdir",
Config{User: "user@domain", Host: "host", Path: "/dir/subdir"},
},
{ {
"sftp:host:../dir/subdir", "sftp:host:../dir/subdir",
Config{Host: "host", Path: "../dir/subdir"}, Config{Host: "host", Path: "../dir/subdir"},