if (path.Contains('\0'))
throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
- // Expand with current directory if necessary
- if (!IsPathRooted(path))
- {
- path = Combine(Interop.Sys.GetCwd(), path);
- }
-
- // We would ideally use realpath to do this, but it resolves symlinks, requires that the file actually exist,
- // and turns it into a full path, which we only want if fullCheck is true.
- string collapsedString = PathInternal.RemoveRelativeSegments(path, PathInternal.GetRootLength(path));
-
- Debug.Assert(collapsedString.Length < path.Length || collapsedString.ToString() == path,
- "Either we've removed characters, or the string should be unmodified from the input path.");
-
- string result = collapsedString.Length == 0 ? PathInternal.DirectorySeparatorCharAsString : collapsedString;
-
- return result;
+ return GetFullPathInternal(path);
}
public static string GetFullPath(string path, string basePath)
throw new ArgumentException(SR.Argument_InvalidPathChars);
if (IsPathFullyQualified(path))
- return GetFullPath(path);
+ return GetFullPathInternal(path);
+
+ return GetFullPathInternal(CombineInternal(basePath, path));
+ }
- return GetFullPath(CombineInternal(basePath, path));
+ // Gets the full path without argument validation
+ private static string GetFullPathInternal(string path)
+ {
+ Debug.Assert(!string.IsNullOrEmpty(path));
+ Debug.Assert(!path.Contains('\0'));
+
+ // Expand with current directory if necessary
+ if (!IsPathRooted(path))
+ {
+ path = Combine(Interop.Sys.GetCwd(), path);
+ }
+
+ // We would ideally use realpath to do this, but it resolves symlinks, requires that the file actually exist,
+ // and turns it into a full path, which we only want if fullCheck is true.
+ string collapsedString = PathInternal.RemoveRelativeSegments(path, PathInternal.GetRootLength(path));
+
+ Debug.Assert(collapsedString.Length < path.Length || collapsedString.ToString() == path,
+ "Either we've removed characters, or the string should be unmodified from the input path.");
+
+ string result = collapsedString.Length == 0 ? PathInternal.DirectorySeparatorCharAsString : collapsedString;
+
+ return result;
}
private static string RemoveLongPathPrefix(string path)
if (path.Contains('\0'))
throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
- return GetFullyQualifiedPath(path);
+ return GetFullPathInternal(path);
}
public static string GetFullPath(string path, string basePath)
throw new ArgumentException(SR.Argument_InvalidPathChars);
if (IsPathFullyQualified(path))
- return GetFullyQualifiedPath(path);
+ return GetFullPathInternal(path);
if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
return basePath;
return PathInternal.IsDevice(combinedPath.AsSpan())
? PathInternal.RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath.AsSpan()))
- : GetFullyQualifiedPath(combinedPath);
+ : GetFullPathInternal(combinedPath);
}
- internal static string GetFullyQualifiedPath(string path)
+ // Gets the full path without argument validation
+ private static string GetFullPathInternal(string path)
{
+ Debug.Assert(!string.IsNullOrEmpty(path));
+ Debug.Assert(!path.Contains('\0'));
+
if (PathInternal.IsExtended(path.AsSpan()))
{
// \\?\ paths are considered normalized by definition. Windows doesn't normalize \\?\