]> git.saurik.com Git - wxWidgets.git/commitdiff
Ensure that wxFileName::GetTempDir() doesn't return trailing slashes.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Jun 2010 11:46:49 +0000 (11:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Jun 2010 11:46:49 +0000 (11:46 +0000)
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

src/common/filename.cpp

index ee6fc1fe17f2c80b655bac3674a902dc61fba493..a51ed78ea2531c7b76942802f111ffcf5a33f387 100644 (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() )