From 16270cd8aea06263057824472a451eea6f3d4d3f Mon Sep 17 00:00:00 2001 From: Steve Berdy <86739818+steveberdy@users.noreply.github.com> Date: Thu, 8 Jul 2021 16:47:25 -0400 Subject: [PATCH 1/3] Update Path.Windows.cs --- .../src/System/IO/Path.Windows.cs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs index 5f4b8e11a1920..95b625e88e2d2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs @@ -49,17 +49,8 @@ public static string GetFullPath(string path) // unpredictable results. if (path.Contains('\0')) throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path)); - - if (PathInternal.IsExtended(path.AsSpan())) - { - // \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\ - // paths and neither should we. Even if we wanted to GetFullPathName does not work - // properly with device paths. If one wants to pass a \\?\ path through normalization - // one can chop off the prefix, pass it to GetFullPath and add it again. - return path; - } - - return PathHelper.Normalize(path); + + return GetFullQualifiedPath(path); } public static string GetFullPath(string path, string basePath) @@ -77,7 +68,7 @@ public static string GetFullPath(string path, string basePath) throw new ArgumentException(SR.Argument_InvalidPathChars); if (IsPathFullyQualified(path)) - return GetFullPath(path); + return GetFullQualifiedPath(path); if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) return basePath; @@ -129,7 +120,21 @@ public static string GetFullPath(string path, string basePath) return PathInternal.IsDevice(combinedPath.AsSpan()) ? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan())) - : GetFullPath(combinedPath); + : GetFullQualifiedPath(combinedPath); + } + + private static string GetFullQualifiedPath(string path) + { + if (PathInternal.IsExtended(path.AsSpan())) + { + // \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\ + // paths and neither should we. Even if we wanted to GetFullPathName does not work + // properly with device paths. If one wants to pass a \\?\ path through normalization + // one can chop off the prefix, pass it to GetFullPath and add it again. + return path; + } + + return PathHelper.Normalize(path); } public static string GetTempPath() From ce6bfd26b32b71c2460088a79c3b2cdc7360e14a Mon Sep 17 00:00:00 2001 From: Steve Berdy <86739818+steveberdy@users.noreply.github.com> Date: Fri, 9 Jul 2021 08:18:11 -0400 Subject: [PATCH 2/3] Change helper method to internal Switched method from a private protection level to an internal protection level. Also removed trailing whitespace. --- .../System.Private.CoreLib/src/System/IO/Path.Windows.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs index 95b625e88e2d2..6737ffbc357b2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs @@ -49,7 +49,7 @@ public static string GetFullPath(string path) // unpredictable results. if (path.Contains('\0')) throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path)); - + return GetFullQualifiedPath(path); } @@ -122,8 +122,8 @@ public static string GetFullPath(string path, string basePath) ? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan())) : GetFullQualifiedPath(combinedPath); } - - private static string GetFullQualifiedPath(string path) + + internal static string GetFullQualifiedPath(string path) { if (PathInternal.IsExtended(path.AsSpan())) { From 376538bda4e78737133fcd34340f655ab28b11b1 Mon Sep 17 00:00:00 2001 From: Jeff Handley Date: Sat, 24 Jul 2021 00:47:38 -0400 Subject: [PATCH 3/3] Rename method to GetFullyQualifiedPath per code review --- .../System.Private.CoreLib/src/System/IO/Path.Windows.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs index 6737ffbc357b2..4d08cd9f24127 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs @@ -50,7 +50,7 @@ public static string GetFullPath(string path) if (path.Contains('\0')) throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path)); - return GetFullQualifiedPath(path); + return GetFullyQualifiedPath(path); } public static string GetFullPath(string path, string basePath) @@ -68,7 +68,7 @@ public static string GetFullPath(string path, string basePath) throw new ArgumentException(SR.Argument_InvalidPathChars); if (IsPathFullyQualified(path)) - return GetFullQualifiedPath(path); + return GetFullyQualifiedPath(path); if (PathInternal.IsEffectivelyEmpty(path.AsSpan())) return basePath; @@ -120,10 +120,10 @@ public static string GetFullPath(string path, string basePath) return PathInternal.IsDevice(combinedPath.AsSpan()) ? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan())) - : GetFullQualifiedPath(combinedPath); + : GetFullyQualifiedPath(combinedPath); } - internal static string GetFullQualifiedPath(string path) + internal static string GetFullyQualifiedPath(string path) { if (PathInternal.IsExtended(path.AsSpan())) {