]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't remove the last slash from "/" directory name under Unix.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 4 May 2012 18:31:48 +0000 (18:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 4 May 2012 18:31:48 +0000 (18:31 +0000)
This was totally wrong as it returned empty string as (invalid) directory
name.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71353 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/unix/dir.cpp
tests/file/dir.cpp

index 111ec6fb62ab4d8af56bef906659233c94d0cd73..197a1565e0f8dc77de64759521a6502756f84526 100644 (file)
@@ -561,6 +561,10 @@ Univ:
 
 - Fix regression with read-only wxComboBox appearance (Jason Erb).
 
+Unix:
+
+- Fix bug with wxDir("/").GetName() returning empty string.
+
 
 
 2.9.3: (released 2011-12-14)
index 9e71c8a40f46384a58e9363ad1cf4ba85b948c6c..b67c9dd9c601f21da6d0d717c522cb178b345b2f 100644 (file)
@@ -235,10 +235,13 @@ wxString wxDir::GetName() const
     if ( m_data )
     {
         name = M_DIR->GetName();
-        if ( !name.empty() && (name.Last() == wxT('/')) )
+
+        // Notice that we need to check for length > 1 as we shouldn't remove
+        // the last slash from the root directory!
+        if ( name.length() > 1 && (name.Last() == wxT('/')) )
         {
-            // chop off the last (back)slash
-            name.Truncate(name.length() - 1);
+            // chop off the last slash
+            name.RemoveLast();
         }
     }
 
index caffd17a6d8448bdf6a9709e753f0c909c3781f0..c5151d243e6d937f4c6ae8631ad3a3e3fb568927 100644 (file)
@@ -41,11 +41,13 @@ private:
         CPPUNIT_TEST( DirExists );
         CPPUNIT_TEST( Traverse );
         CPPUNIT_TEST( Enum );
+        CPPUNIT_TEST( GetName );
     CPPUNIT_TEST_SUITE_END();
 
     void DirExists();
     void Traverse();
     void Enum();
+    void GetName();
 
     void CreateTempFile(const wxString& path);
     wxArrayString DirEnumHelper(wxDir& dir,
@@ -227,3 +229,15 @@ void DirTestCase::DirExists()
     CPPUNIT_ASSERT( wxDir::Exists(wxGetCwd()) );
 }
 
+void DirTestCase::GetName()
+{
+    wxDir d;
+
+    CPPUNIT_ASSERT( d.Open(".") );
+    CPPUNIT_ASSERT( d.GetName().Last() != wxFILE_SEP_PATH );
+
+#ifdef __UNIX__
+    CPPUNIT_ASSERT( d.Open("/") );
+    CPPUNIT_ASSERT_EQUAL( "/", d.GetName() );
+#endif
+}