From: Vadim Zeitlin Date: Sun, 20 Jun 2010 11:46:49 +0000 (+0000) Subject: Ensure that wxFileName::GetTempDir() doesn't return trailing slashes. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/02f35bffeb7e26b6163a027b827692ff4851f3b2 Ensure that wxFileName::GetTempDir() doesn't return trailing slashes. Sanitize the value returned by GetTempDir() to ensure that it doesn't have any trailing path separators. This happened at least under OS X where standard TMPDIR has a trailing slash and was inconsistent with the behaviour under the other platforms. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64638 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/filename.cpp b/src/common/filename.cpp index ee6fc1fe17..a51ed78ea2 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1194,6 +1194,21 @@ wxString wxFileName::GetTempDir() dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder); #endif // systems with native way } + else // we got directory from an environment variable + { + // remove any trailing path separators, we don't want to ever return + // them from this function for consistency + const size_t lastNonSep = dir.find_last_not_of(GetPathSeparators()); + if ( lastNonSep == wxString::npos ) + { + // the string consists entirely of separators, leave only one + dir = GetPathSeparator(); + } + else + { + dir.erase(lastNonSep + 1); + } + } // fall back to hard coded value if ( dir.empty() )