diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index e52e438b43..b5997b8419 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -452,7 +452,7 @@ namespace Umbraco.ModelsBuilder.Embedded try { var assemblyPath = GetOutputAssemblyPath(currentHash); - RoslynCompiler.CompileToFile(_hostingEnvironment.MapPathContentRoot(projFile), assemblyPath); + RoslynCompiler.CompileToFile(projFile, assemblyPath); assembly = ReloadAssembly(assemblyPath); File.WriteAllText(dllPathFile, assembly.Location); File.WriteAllText(modelsHashFile, currentHash); @@ -494,7 +494,7 @@ namespace Umbraco.ModelsBuilder.Embedded try { var assemblyPath = GetOutputAssemblyPath(currentHash); - RoslynCompiler.CompileToFile(_hostingEnvironment.MapPathContentRoot(projFile), assemblyPath); + RoslynCompiler.CompileToFile(projFile, assemblyPath); assembly = ReloadAssembly(assemblyPath); File.WriteAllText(dllPathFile, assemblyPath); File.WriteAllText(modelsHashFile, currentHash); diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs index 21301bc01a..a78565c977 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -79,16 +79,13 @@ namespace Umbraco.Web.Common.AspNetCore } } - public string MapPathWebRoot(string path) - { - var newPath = path.TrimStart('~', '/').Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); - return Path.Combine(_webHostEnvironment.WebRootPath, newPath); - } + public string MapPathWebRoot(string path) => MapPath(_webHostEnvironment.WebRootPath, path); + public string MapPathContentRoot(string path) => MapPath(_webHostEnvironment.ContentRootPath, path); - public string MapPathContentRoot(string path) + private string MapPath(string root, string path) { - var newPath = path.TrimStart('~', '/').Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); - return Path.Combine(_webHostEnvironment.ContentRootPath, newPath); + var newPath = path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); + return newPath.StartsWith(root) ? newPath : Path.Combine(root, newPath.TrimStart('~', '/')); } public string ToAbsolute(string virtualPath) diff --git a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs index 8b9cfe7aa6..cc8fc975d2 100644 --- a/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs @@ -49,7 +49,8 @@ namespace Umbraco.Web.Hosting return HostingEnvironment.MapPath(path); // this will be the case in unit tests, we'll manually map the path - return Path.Combine(ApplicationPhysicalPath, path.TrimStart('~', '/')); + var newPath = path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); + return newPath.StartsWith(ApplicationPhysicalPath) ? newPath : Path.Combine(ApplicationPhysicalPath, newPath.TrimStart('~', '/')); } public string MapPathContentRoot(string path) => MapPathWebRoot(path);