2005-11-10 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Thu, 10 Nov 2005 16:22:29 +0000 (16:22 -0000)
committerDick Porter <dick@acm.org>
Thu, 10 Nov 2005 16:22:29 +0000 (16:22 -0000)
        * DirectoryInfo.cs: Fix endless recursion problem with root
        directory on windows too.  Fixes bug 76191.

svn path=/trunk/mcs/; revision=52853

mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/DirectoryInfo.cs
mcs/class/corlib/Test/System.IO/PathTest.cs

index be3088f27991d5051b13a3d00078690fe0521acc..1beb7c4f600958ad128361b375b8692653890595 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-10  Dick Porter  <dick@ximian.com>
+
+       * DirectoryInfo.cs: Fix endless recursion problem with root
+       directory on windows too.  Fixes bug 76191.
+
 2005-11-06  Zoltan Varga  <vargaz@freemail.hu>
 
        * Directory.cs: Add stub for net 2.0 GetFiles method.
index 1487043de4f434e4dff5f1cb08ca1b8a1dfef2f8..f931a9a2033e71e8c45d24f8478e1279844ebfe7 100644 (file)
@@ -48,7 +48,7 @@ namespace System.IO {
                        FullPath = Path.GetFullPath (path);
 
                        // Path.GetFullPath ends with / when it's the root directory (fix endless recursion problem)
-                       if ((path.Length > 1) || ((path [0] != Path.DirectorySeparatorChar) && (path [0] != Path.AltDirectorySeparatorChar))) {
+                       if (Path.GetPathRoot (path) != path) {
                                char end = path [path.Length - 1];
                                if ((end == Path.DirectorySeparatorChar) || (end == Path.AltDirectorySeparatorChar))
                                        FullPath += Path.DirectorySeparatorChar;
index e0157dff4f50471dd04138cee8add751786cc02f..057be029eadfdd82031346f96249746f219df097 100644 (file)
@@ -259,6 +259,16 @@ namespace MonoTests.System.IO
                        } catch (Exception e) {
                                AssertEquals ("GetDirectoryName Exc. #03", typeof (ArgumentException), e.GetType ());
                        }
+
+                       if (Windows) {
+                               AssertEquals ("GetDirectoryName #04", null, Path.GetDirectoryName ("C:"));
+                               AssertEquals ("GetDirectoryName #05", null, Path.GetDirectoryName (@"C:\"));
+                               AssertEquals ("GetDirectoryName #06", @"C:\", Path.GetDirectoryName (@"C:\dir"));
+                               AssertEquals ("GetDirectoryName #07", @"C:\dir", Path.GetDirectoryName (@"C:\dir\"));
+                               AssertEquals ("GetDirectoryName #08", @"C:\dir", Path.GetDirectoryName (@"C:\dir\dir"));
+                               AssertEquals ("GetDirectoryName #09", @"C:\dir\dir", Path.GetDirectoryName (@"C:\dir\dir\"));
+                       }
+                                       
                }
 
                public void TestGetExtension ()
@@ -508,6 +518,8 @@ namespace MonoTests.System.IO
                                AssertEquals ("GetPathRoot w#12", String.Empty, Path.GetPathRoot ("abc//def"));
                                AssertEquals ("GetPathRoot w#13", "\\", Path.GetPathRoot ("/abc/def"));
                                AssertEquals ("GetPathRoot w#14", "\\\\abc\\def", Path.GetPathRoot ("//abc/def"));
+                               AssertEquals ("GetPathRoot w#15", @"C:\", Path.GetPathRoot (@"C:\"));
+                               AssertEquals ("GetPathRoot w#16", @"C:\", Path.GetPathRoot (@"C:\\"));
                        } else {
                                // TODO: Same tests for Unix.
                        }