Skip to content

Commit 003e09e

Browse files
authored
Fix duplicated path.Contains check and other checks in Path.GetFullPath (#55373)
1 parent 4651ead commit 003e09e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ public static string GetFullPath(string path)
5050
if (path.Contains('\0'))
5151
throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
5252

53-
if (PathInternal.IsExtended(path.AsSpan()))
54-
{
55-
// \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\
56-
// paths and neither should we. Even if we wanted to GetFullPathName does not work
57-
// properly with device paths. If one wants to pass a \\?\ path through normalization
58-
// one can chop off the prefix, pass it to GetFullPath and add it again.
59-
return path;
60-
}
61-
62-
return PathHelper.Normalize(path);
53+
return GetFullyQualifiedPath(path);
6354
}
6455

6556
public static string GetFullPath(string path, string basePath)
@@ -77,7 +68,7 @@ public static string GetFullPath(string path, string basePath)
7768
throw new ArgumentException(SR.Argument_InvalidPathChars);
7869

7970
if (IsPathFullyQualified(path))
80-
return GetFullPath(path);
71+
return GetFullyQualifiedPath(path);
8172

8273
if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
8374
return basePath;
@@ -129,7 +120,21 @@ public static string GetFullPath(string path, string basePath)
129120

130121
return PathInternal.IsDevice(combinedPath.AsSpan())
131122
? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan()))
132-
: GetFullPath(combinedPath);
123+
: GetFullyQualifiedPath(combinedPath);
124+
}
125+
126+
internal static string GetFullyQualifiedPath(string path)
127+
{
128+
if (PathInternal.IsExtended(path.AsSpan()))
129+
{
130+
// \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\
131+
// paths and neither should we. Even if we wanted to GetFullPathName does not work
132+
// properly with device paths. If one wants to pass a \\?\ path through normalization
133+
// one can chop off the prefix, pass it to GetFullPath and add it again.
134+
return path;
135+
}
136+
137+
return PathHelper.Normalize(path);
133138
}
134139

135140
public static string GetTempPath()

0 commit comments

Comments
 (0)