Skip to content

Commit

Permalink
Fix duplicated path.Contains check and other checks in Path.GetFullPa…
Browse files Browse the repository at this point in the history
…th (#55373)
  • Loading branch information
steveberdy authored Jul 24, 2021
1 parent 4651ead commit 003e09e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ public static string GetFullPath(string path)
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 GetFullyQualifiedPath(path);
}

public static string GetFullPath(string path, string basePath)
Expand All @@ -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 GetFullyQualifiedPath(path);

if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
return basePath;
Expand Down Expand Up @@ -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);
: GetFullyQualifiedPath(combinedPath);
}

internal static string GetFullyQualifiedPath(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()
Expand Down

0 comments on commit 003e09e

Please sign in to comment.