From 065ae50868574404c502fb8b9508a2475d218337 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Thu, 19 Dec 2024 08:54:22 -0500 Subject: [PATCH] Improve parsing logic for swift storage URLs that contain multiple '@' Parse the storage URL first, then use a regex to ensure the server name is correctly identified starting after the final '@'. --- src/duplicacy_swiftstorage.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/duplicacy_swiftstorage.go b/src/duplicacy_swiftstorage.go index 5c26747..61bd39a 100644 --- a/src/duplicacy_swiftstorage.go +++ b/src/duplicacy_swiftstorage.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "time" + "regexp" "github.com/ncw/swift/v2" ) @@ -42,13 +43,6 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw } } - // Take out the user name if there is one - if strings.Contains(storageURL, "@") { - userAndURL := strings.Split(storageURL, "@") - arguments["user"] = userAndURL[0] - storageURL = userAndURL[1] - } - // The version is used to split authURL and container/path versions := []string{"/v1/", "/v1.0/", "/v2/", "/v2.0/", "/v3/", "/v3.0/", "/v4/", "/v4.0/"} storageDir := "" @@ -60,6 +54,17 @@ func CreateSwiftStorage(storageURL string, key string, threads int) (storage *Sw } } + // Take out the user name if there is one + if strings.Contains(storageURL, "@") { + // Use regex to split the username and the rest of the URL + lineRegex := regexp.MustCompile(`^(.+)@([^@]+)$`) + match := lineRegex.FindStringSubmatch(storageURL) + if match != nil { + arguments["user"] = match[1] + storageURL = match[2] + } + } + // If no container/path is specified, find them from the arguments if storageDir == "" { storageDir = arguments["storage_dir"]