Remove check for path starting with root, assume path is always relative to the root

This commit is contained in:
Benjamin Carleski
2020-11-19 03:24:42 -08:00
parent 42f4fdf8c8
commit 7faf79b818

View File

@@ -85,7 +85,15 @@ namespace Umbraco.Web.Common.AspNetCore
private string MapPath(string root, string path)
{
var newPath = path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar);
return newPath.StartsWith(root) ? newPath : Path.Combine(root, newPath.TrimStart('~', '/'));
// TODO: This is a temporary error because we switched from IOHelper.MapPath to HostingEnvironment.MapPathXXX
// IOHelper would check if the path passed in started with the root, and not prepend the root again if it did,
// however if you are requesting a path be mapped, it should always assume the path is relative to the root, not
// absolute in the file system. This error will help us find and fix improper uses, and should be removed once
// all those uses have been found and fixed
if (newPath.StartsWith(root)) throw new ArgumentException("The path appears to already be fully qualified. Please remove the call to MapPath");
return Path.Combine(root, newPath.TrimStart('~', '/'));
}
public string ToAbsolute(string virtualPath)