diff options
author | dotnet bot <dotnet-bot@dotnetfoundation.org> | 2017-05-05 01:23:37 +0300 |
---|---|---|
committer | Viktor Hofer <viktor.hofer@microsoft.com> | 2017-05-05 01:23:37 +0300 |
commit | a5ecd296d051c113482182217fcd6595ab5d95e6 (patch) | |
tree | 5757e7c413ad29f8b678dc29f29eb3c02643bef5 /src/System.Private.CoreLib/shared/System | |
parent | 622f7e2c665e9fcac0b9ced4e123ce315d09e38f (diff) |
System.IO.Path.GetPathRoot string.Empty or whitespace character string should throw ArgumentException (#11387) (#3521)
* GetPathRoot string.Empty and string whitespace throws ArgumentException
* throw in next line
* Refined method description
* Unix impl adjusted
* Indentation
* pr feedback
* Delete Path.Unix.cs
* Adding param to ArgumentException
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src/System.Private.CoreLib/shared/System')
-rw-r--r-- | src/System.Private.CoreLib/shared/System/IO/Path.Unix.cs | 9 | ||||
-rw-r--r-- | src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/System.Private.CoreLib/shared/System/IO/Path.Unix.cs b/src/System.Private.CoreLib/shared/System/IO/Path.Unix.cs index 500c60aa8..68c5f7003 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Path.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Path.Unix.cs @@ -23,7 +23,7 @@ namespace System.IO throw new ArgumentNullException(nameof(path)); if (path.Length == 0) - throw new ArgumentException(SR.Arg_PathIllegal); + throw new ArgumentException(SR.Arg_PathIllegal, nameof(path)); PathInternal.CheckInvalidPathChars(path); @@ -193,10 +193,15 @@ namespace System.IO return path.Length > 0 && path[0] == PathInternal.DirectorySeparatorChar; } + // The resulting string is null if path is null. If the path is empty or + // only contains whitespace characters an ArgumentException gets thrown. public static string GetPathRoot(string path) { if (path == null) return null; - return IsPathRooted(path) ? PathInternal.DirectorySeparatorCharAsString : String.Empty; + if (string.IsNullOrWhiteSpace(path)) + throw new ArgumentException(SR.Arg_PathIllegal, nameof(path)); + + return IsPathRooted(path) ? PathInternal.DirectorySeparatorCharAsString : String.Empty; } /// <summary>Gets whether the system is case-sensitive.</summary> diff --git a/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs index d6f0c628c..1e573cd95 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Path.Windows.cs @@ -136,10 +136,14 @@ namespace System.IO // path on the current drive), "X:" (a relative path on a given drive, // where X is the drive letter), "X:\" (an absolute path on a given drive), // and "\\server\share" (a UNC path for a given server and share name). - // The resulting string is null if path is null. + // The resulting string is null if path is null. If the path is empty or + // only contains whitespace characters an ArgumentException gets thrown. public static string GetPathRoot(string path) { if (path == null) return null; + if (string.IsNullOrWhiteSpace(path)) + throw new ArgumentException(SR.Arg_PathIllegal, nameof(path)); + PathInternal.CheckInvalidPathChars(path); // Need to return the normalized directory separator |