diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 13629a51af..b664a5ef5a 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1608,6 +1608,11 @@ bool wxFileName::ReplaceHomeDir(wxPathFormat format) if (homedir.empty()) return false; + // Avoid replacing the leading "/" with "~", this would result in an + // invalid path, if nothing else + if (homedir == '/') + return true; // but it is not an error, so don't return false + wxString stringForm = GetPath(wxPATH_GET_VOLUME, format); // do not touch the file name and the extension diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index 4bc97850b5..4327cf2307 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -466,7 +466,16 @@ TEST_CASE("wxFileName::Replace", "[filename]") // now test ReplaceHomeDir - wxFileName fn = wxFileName::DirName(wxGetHomeDir()); + const wxString& homedir = wxGetHomeDir(); + if ( homedir == "/" ) + { + // These tests assume that HOME is a non-root directory, but this may + // not be the case. + WARN("Skipping wxFileName::ReplaceHomeDir() tests because HOME=/"); + return; + } + + wxFileName fn = wxFileName::DirName(homedir); fn.AppendDir("test1"); fn.AppendDir("test2"); fn.AppendDir("test3");