diff options
Diffstat (limited to 'src/mscorlib/shared/System/IO/Path.cs')
-rw-r--r-- | src/mscorlib/shared/System/IO/Path.cs | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/mscorlib/shared/System/IO/Path.cs b/src/mscorlib/shared/System/IO/Path.cs index b3a8783c32..9feb2873d8 100644 --- a/src/mscorlib/shared/System/IO/Path.cs +++ b/src/mscorlib/shared/System/IO/Path.cs @@ -76,19 +76,23 @@ namespace System.IO // "\\server\share"). public static string GetDirectoryName(string path) { - if (path != null) + if (string.IsNullOrWhiteSpace(path)) { - PathInternal.CheckInvalidPathChars(path); - path = PathInternal.NormalizeDirectorySeparators(path); - int root = PathInternal.GetRootLength(path); + if (path == null) return null; + throw new ArgumentException(SR.Arg_PathIllegal, nameof(path)); + } - int i = path.Length; - if (i > root) - { - while (i > root && !PathInternal.IsDirectorySeparator(path[--i])) ; - return path.Substring(0, i); - } + PathInternal.CheckInvalidPathChars(path); + path = PathInternal.NormalizeDirectorySeparators(path); + int root = PathInternal.GetRootLength(path); + + int i = path.Length; + if (i > root) + { + while (i > root && !PathInternal.IsDirectorySeparator(path[--i])) ; + return path.Substring(0, i); } + return null; } |