From: Roman Marusyk Date: Sun, 23 Jun 2019 02:55:17 +0000 (+0300) Subject: Change exception throwing in Path.GetRelativePath (#25047) X-Git-Tag: accepted/tizen/unified/20190813.215958~40^2~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=717b32703b59682479c04399c03fe0ebfa79c22f;p=platform%2Fupstream%2Fcoreclr.git Change exception throwing in Path.GetRelativePath (#25047) * Fix Path.GetRelativePath throws ArgumentNullException when relativeTo is empty string * Fix ArgumentException for relativeTo --- diff --git a/src/System.Private.CoreLib/shared/System/IO/Path.cs b/src/System.Private.CoreLib/shared/System/IO/Path.cs index 7412eb6..c581ee6 100644 --- a/src/System.Private.CoreLib/shared/System/IO/Path.cs +++ b/src/System.Private.CoreLib/shared/System/IO/Path.cs @@ -812,8 +812,18 @@ namespace System.IO private static string GetRelativePath(string relativeTo, string path, StringComparison comparisonType) { - if (string.IsNullOrEmpty(relativeTo)) throw new ArgumentNullException(nameof(relativeTo)); - if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) throw new ArgumentNullException(nameof(path)); + if (relativeTo == null) + throw new ArgumentNullException(nameof(relativeTo)); + + if (PathInternal.IsEffectivelyEmpty(relativeTo.AsSpan())) + throw new ArgumentException(SR.Arg_PathEmpty, nameof(relativeTo)); + + if (path == null) + throw new ArgumentNullException(nameof(path)); + + if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) + throw new ArgumentException(SR.Arg_PathEmpty, nameof(path)); + Debug.Assert(comparisonType == StringComparison.Ordinal || comparisonType == StringComparison.OrdinalIgnoreCase); relativeTo = GetFullPath(relativeTo);