if (IsPathFullyQualified(path))
return GetFullPath(path);
+ if (PathInternal.IsEffectivelyEmpty(path))
+ return basePath;
+
int length = path.Length;
string combinedPath = null;
// Path is current drive rooted i.e. starts with \:
// "\Foo" and "C:\Bar" => "C:\Foo"
// "\Foo" and "\\?\C:\Bar" => "\\?\C:\Foo"
- combinedPath = Join(GetPathRoot(basePath.AsSpan()), path);
+ combinedPath = Join(GetPathRoot(basePath.AsSpan()), path.AsSpan().Slice(1)); // Cut the separator to ensure we don't end up with two separators when joining with the root.
}
else if (length >= 2 && PathInternal.IsValidDriveChar(path[0]) && path[1] == PathInternal.VolumeSeparatorChar)
{
// to GetFullPath() won't do anything by design. Additionally, GetFullPathName() in
// Windows doesn't root them properly. As such we need to manually remove segments.
return PathInternal.IsDevice(combinedPath)
- ? RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath))
+ // Paths at this point are in the form of \\?\C:\.\tmp we skip to the last character of the root when calling RemoveRelativeSegments to remove relative paths in such cases.
+ ? RemoveRelativeSegments(combinedPath, PathInternal.GetRootLength(combinedPath) - 1)
: GetFullPath(combinedPath);
}