From eff65647958c2fcc2a82cf7975848b7c772e97d9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 Aug 2019 14:28:46 +0200 Subject: [PATCH] Don't expand environment variables in wxFileName::MakeRelativeTo() This could have been unexpected even if it worked as designed and, unlike with direct calls to Normalize(), there was no way to prevent this from happening. Worse, even when no expansion was done, the simple fact of calling wxExpandEnvVars() could result in replacing "dir\$file" with "dir$file" as the backslash is considered as an escape character by this function and hence break the file name structure. Closes #17977. --- src/common/filename.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/filename.cpp b/src/common/filename.cpp index d7f1e1ce43..fa5a24fe43 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1710,10 +1710,12 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format) // get cwd only once - small time saving wxString cwd = wxGetCwd(); - // Normalize the paths but avoid changing the case or turning a shortcut - // into a file that it points to. - const int normFlags = wxPATH_NORM_ALL & - ~(wxPATH_NORM_CASE | wxPATH_NORM_SHORTCUT); + // Normalize both paths to be absolute but avoid expanding environment + // variables in them, this could be unexpected. + const int normFlags = wxPATH_NORM_DOTS | + wxPATH_NORM_TILDE | + wxPATH_NORM_ABSOLUTE | + wxPATH_NORM_LONG; Normalize(normFlags, cwd, format); fnBase.Normalize(normFlags, cwd, format);