diff --git a/include/wx/filename.h b/include/wx/filename.h index 5722daf8ff..ef108760e2 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -361,7 +361,7 @@ public: bool MakeRelativeTo(const wxString& pathBase = wxEmptyString, wxPathFormat format = wxPATH_NATIVE); - // make the path absolute + // make the path absolute and resolve any "." and ".." in it // // this may be done using another (than current) value of cwd bool MakeAbsolute(const wxString& cwd = wxEmptyString, diff --git a/samples/menu/menu.cpp b/samples/menu/menu.cpp index 3adf4db013..f325fbf07c 100644 --- a/samples/menu/menu.cpp +++ b/samples/menu/menu.cpp @@ -575,15 +575,15 @@ MyFrame::MyFrame() m_fileHistory->UseMenu(m_fileHistoryMenu); wxFileName fn( "menu.cpp" ); - fn.Normalize(); + fn.MakeAbsolute(); m_fileHistory->AddFileToHistory( fn.GetFullPath() ); fn = "Makefile.in"; - fn.Normalize(); + fn.MakeAbsolute(); m_fileHistory->AddFileToHistory( fn.GetFullPath() ); fn.Assign("minimal", "minimal", "cpp"); - fn.Normalize(); + fn.MakeAbsolute(); m_fileHistory->AddFileToHistory( fn.GetFullPath() ); fileMenu->AppendSubMenu(m_fileHistoryMenu, "Sample file history"); diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 5d96f045fd..8688e92a66 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1765,14 +1765,14 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format) // get cwd only once - small time saving wxString cwd = wxGetCwd(); - // 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); + // Bring both paths to canonical form. + MakeAbsolute(cwd, format); + fnBase.MakeAbsolute(cwd, format); + + // Do this here for compatibility, as we used to do it before. + Normalize(wxPATH_NORM_LONG, cwd, format); + fnBase.Normalize(wxPATH_NORM_LONG, cwd, format); + bool withCase = IsCaseSensitive(format); @@ -2620,7 +2620,7 @@ static wxString EscapeFileNameCharsInURL(const char *in) wxString wxFileName::FileNameToURL(const wxFileName& filename) { wxFileName fn = filename; - fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE); + fn.MakeAbsolute(); wxString url = fn.GetFullPath(wxPATH_NATIVE); #ifndef __UNIX__ diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index e8e4fe1145..73d927d59f 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -201,8 +201,8 @@ TEST_CASE("wxFileName::Comparison", "[filename]") { wxFileName fn1(wxT("/tmp/file1")); wxFileName fn2(wxT("/tmp/dir2/../file2")); - fn1.Normalize(); - fn2.Normalize(); + fn1.MakeAbsolute(); + fn2.MakeAbsolute(); CHECK(fn1.GetPath() == fn2.GetPath()); }