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
This commit is contained in:
Vadim Zeitlin 2010-06-20 11:46:49 +00:00
parent 7c2257892c
commit 02f35bffeb

View File

@ -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() )