Merge pull request #3274 from Unity-Technologies/fix-path-getfullpath-windows
authorMarek Safar <marek.safar@gmail.com>
Fri, 15 Jul 2016 08:31:33 +0000 (10:31 +0200)
committerGitHub <noreply@github.com>
Fri, 15 Jul 2016 08:31:33 +0000 (10:31 +0200)
Fix Path.GetFullPath for roots on Windows

mcs/class/corlib/System.IO/Path.cs
mcs/class/corlib/Test/System.IO/PathTest.cs

index fc62a4db6e3bff42240dfdca7c37c83252c7e266..d0512f24695a2a5dbe3111080092742268f8da45 100644 (file)
@@ -320,9 +320,12 @@ namespace System.IO {
 
                internal static string WindowsDriveAdjustment (string path)
                {
-                       // two special cases to consider when a drive is specified
-                       if (path.Length < 2)
+                       // three special cases to consider when a drive is specified
+                       if (path.Length < 2) {
+                               if (path.Length == 1 && (path[0] == '\\' || path[0] == '/'))
+                                       return Path.GetPathRoot(Directory.GetCurrentDirectory());
                                return path;
+                       }
                        if ((path [1] != ':') || !Char.IsLetter (path [0]))
                                return path;
 
index 897342eba7f20d6483be863287879c2b469029e1..c3ab9935350c9b1f3071960bda46d06d97b74d81 100644 (file)
@@ -688,6 +688,11 @@ namespace MonoTests.System.IO
                                                i, root + test [i, 0], ex.GetType ()));
                                }
                        }
+
+                       // These cases require that we don't pass a root to GetFullPath - it should return the proper drive root.
+                       string root4 = Path.GetPathRoot(Directory.GetCurrentDirectory());
+                       Assert.AreEqual(root4, Path.GetFullPath(@"\"));
+                       Assert.AreEqual(root4, Path.GetFullPath("/"));
                }
 
                [Test]