From 7faf79b8187a85e99e3681f79ca92f70e30b67ce Mon Sep 17 00:00:00 2001 From: Benjamin Carleski Date: Thu, 19 Nov 2020 03:24:42 -0800 Subject: [PATCH] Remove check for path starting with root, assume path is always relative to the root --- .../AspNetCore/AspNetCoreHostingEnvironment.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index a78565c977..ea2efc5b1b 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -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)