From cce798ceac5b3b56719cded511e89339a9dbf5df Mon Sep 17 00:00:00 2001 From: Patrick Seal Date: Tue, 18 Sep 2018 11:16:31 -0700 Subject: [PATCH] Replace special characters in environment variable name with underscores --- src/duplicacy_utils.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/duplicacy_utils.go b/src/duplicacy_utils.go index 1bfa728..8582b4e 100644 --- a/src/duplicacy_utils.go +++ b/src/duplicacy_utils.go @@ -176,6 +176,15 @@ func GetPasswordFromPreference(preference Preference, passwordType string) strin if password, found := os.LookupEnv(name); found && password != "" { return password } + + re := regexp.MustCompile(`[^a-zA-Z0-9_]`) + namePlain := re.ReplaceAllString(name, "_") + if namePlain != name { + LOG_DEBUG("PASSWORD_ENV_VAR", "Reading the environment variable %s", namePlain) + if password, found := os.LookupEnv(namePlain); found && password != "" { + return password + } + } } // If the password is stored in the preference, there is no need to include the storage name