Fix Path.GetFullPath for roots on Windows
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;
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]