From c9aa6cf5fb05e2e562b5bc500fcd3ef44ae08c76 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Sat, 21 Oct 2017 09:21:07 -0700 Subject: [PATCH] Avoid performing tilde expansion. The expansion being performed was often incorrect, as it's possible for the tilde character to appear as part of the path where it should not be expanded to the user's home directory. Properly supporting tilde expansion is complicated and requires additional study. Instead of supporting it only partially, we have decided to simplify things and just drop tilde expansion for now. See the discussion in issue #2619, as well as issues #2325 and #2555. --- Duplicati/Library/Utility/Utility.cs | 10 ++++------ Duplicati/UnitTest/BasicSetupHelper.cs | 2 +- Duplicati/UnitTest/GeneralBlackBoxTesting.cs | 2 +- Duplicati/UnitTest/SVNCheckoutsTest.cs | 5 ----- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Duplicati/Library/Utility/Utility.cs b/Duplicati/Library/Utility/Utility.cs index 12d42bf21..78da0a201 100644 --- a/Duplicati/Library/Utility/Utility.cs +++ b/Duplicati/Library/Utility/Utility.cs @@ -977,13 +977,13 @@ namespace Duplicati.Library.Utility public static readonly string HOME_PATH = Environment.GetFolderPath(IsClientLinux ? Environment.SpecialFolder.Personal : Environment.SpecialFolder.UserProfile); /// - /// Expands environment variables, including the tilde character + /// Expands environment variables. /// /// The expanded string. /// The string to expand. public static string ExpandEnvironmentVariables(string str) { - return Environment.ExpandEnvironmentVariables(str.Replace("~", HOME_PATH)); + return Environment.ExpandEnvironmentVariables(str); } /// @@ -997,7 +997,7 @@ namespace Duplicati.Library.Utility private static readonly Regex ENVIRONMENT_VARIABLE_MATCHER_LINUX = new Regex(@"\$(?\w+)|(\{(?[^\}]+)\})"); /// - /// Expands environment variables, including the tilde character, in a RegExp safe format + /// Expands environment variables in a RegExp safe format /// /// The expanded string. /// The string to expand. @@ -1012,9 +1012,7 @@ namespace Duplicati.Library.Utility // TODO: Should we switch to using the native format, instead of following the Windows scheme? //IsClientLinux ? ENVIRONMENT_VARIABLE_MATCHER_LINUX : ENVIRONMENT_VARIABLE_MATCHER_WINDOWS - ENVIRONMENT_VARIABLE_MATCHER_WINDOWS - .Replace(str.Replace("~", Regex.Escape(HOME_PATH)), (m) => - Regex.Escape(lookup(m.Groups["name"].Value))); + ENVIRONMENT_VARIABLE_MATCHER_WINDOWS.Replace(str, (m) => Regex.Escape(lookup(m.Groups["name"].Value))); } /// diff --git a/Duplicati/UnitTest/BasicSetupHelper.cs b/Duplicati/UnitTest/BasicSetupHelper.cs index ce045a3da..f039f2cb8 100644 --- a/Duplicati/UnitTest/BasicSetupHelper.cs +++ b/Duplicati/UnitTest/BasicSetupHelper.cs @@ -29,7 +29,7 @@ namespace Duplicati.UnitTest /// protected static readonly string BASEFOLDER = string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER")) - ? Library.Utility.Utility.ExpandEnvironmentVariables(Path.Combine("~", "testdata")) + ? Path.Combine(Library.Utility.Utility.HOME_PATH, "testdata") : Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER"); /// diff --git a/Duplicati/UnitTest/GeneralBlackBoxTesting.cs b/Duplicati/UnitTest/GeneralBlackBoxTesting.cs index 9143d128f..fb9e508ec 100644 --- a/Duplicati/UnitTest/GeneralBlackBoxTesting.cs +++ b/Duplicati/UnitTest/GeneralBlackBoxTesting.cs @@ -29,7 +29,7 @@ namespace Duplicati.UnitTest private static readonly string SOURCE_FOLDERS = Path.Combine( string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER")) - ? Library.Utility.Utility.ExpandEnvironmentVariables(Path.Combine("~", "testdata")) + ? Path.Combine(Library.Utility.Utility.HOME_PATH, "testdata") : Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER") , "DSMCBE"); diff --git a/Duplicati/UnitTest/SVNCheckoutsTest.cs b/Duplicati/UnitTest/SVNCheckoutsTest.cs index 74107abf4..3416c09e0 100644 --- a/Duplicati/UnitTest/SVNCheckoutsTest.cs +++ b/Duplicati/UnitTest/SVNCheckoutsTest.cs @@ -99,11 +99,6 @@ namespace Duplicati.UnitTest where !string.IsNullOrWhiteSpace(x) select Library.Utility.Utility.ExpandEnvironmentVariables(x)).ToArray(); - //Expand the tilde to home folder on Linux/OSX - if (Utility.IsClientLinux) - folders = (from x in folders - select x.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal))).ToArray(); - foreach (var f in folders) foreach (var n in f.Split(new char[] { System.IO.Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries)) if (!System.IO.Directory.Exists(n))