Don't pass in Root to ToAbsolute there's no need

This commit is contained in:
Shannon
2020-04-03 09:17:40 +11:00
parent fa2e9c3715
commit 1224c97f07
4 changed files with 8 additions and 13 deletions

View File

@@ -23,16 +23,14 @@ namespace Umbraco.Core.Hosting
/// Maps a virtual path to the application's web root
/// </summary>
/// <param name="virtualPath">The virtual path. Must start with either ~/ or / else an exception is thrown.</param>
/// <param name="root">The absolute web root value. Must start with / else an exception is thrown.</param>
/// <returns></returns>
/// <remarks>
/// This maps the virtual path syntax to the web root. For example when hosting in a virtual directory called "site" and the value "~/pages/test" is passed in, it will
/// map to "/site/pages/test" where "/site" is the value of root.
/// map to "/site/pages/test" where "/site" is the value of <see cref="ApplicationVirtualPath"/>.
/// </remarks>
/// <exception cref="InvalidOperationException">
/// If virtualPath does not start with ~/ or /
/// If root does not start with /
/// </exception>
string ToAbsolute(string virtualPath, string root);
string ToAbsolute(string virtualPath);
}
}

View File

@@ -56,8 +56,7 @@ namespace Umbraco.Core.IO
public string ResolveUrl(string virtualPath)
{
if (string.IsNullOrWhiteSpace(virtualPath)) return virtualPath;
// TODO: This is a bit odd, the whole "Root" thing is strange, we're passing this into IHostingEnvironment, but it already should know this value in it's ApplicationVirtualPath
return _hostingEnvironment.ToAbsolute(virtualPath, Root);
return _hostingEnvironment.ToAbsolute(virtualPath);
}
@@ -70,8 +69,7 @@ namespace Umbraco.Core.IO
if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
return Attempt.Succeed(virtualPath);
// TODO: This is a bit odd, the whole "Root" thing is strange, we're passing this into IHostingEnvironment, but it already should know this value in it's ApplicationVirtualPath
return Attempt.Succeed(_hostingEnvironment.ToAbsolute(virtualPath, Root));
return Attempt.Succeed(_hostingEnvironment.ToAbsolute(virtualPath));
}
catch (Exception ex)
{

View File

@@ -86,13 +86,12 @@ namespace Umbraco.Web.Common.AspNetCore
return Path.Combine(_webHostEnvironment.WebRootPath, newPath);
}
// TODO: Need to take into account 'root' here, maybe not, Root probably shouldn't be a param, see notes in IOHelper that calls this, we already know ApplicationVirtualPath
public string ToAbsolute(string virtualPath, string root)
public string ToAbsolute(string virtualPath)
{
if (!virtualPath.StartsWith("~/") && !virtualPath.StartsWith("/"))
throw new InvalidOperationException($"{nameof(virtualPath)} must start with ~/ or /");
if (!root.StartsWith("/"))
throw new InvalidOperationException($"{nameof(virtualPath)} must start with /");
var root = ApplicationVirtualPath.EnsureStartsWith('/');
// will occur if it starts with "/"
if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))

View File

@@ -41,7 +41,7 @@ namespace Umbraco.Web.Hosting
return HostingEnvironment.MapPath(path);
}
public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root.EnsureStartsWith('/'));
public string ToAbsolute(string virtualPath) => VirtualPathUtility.ToAbsolute(virtualPath, ApplicationVirtualPath.EnsureStartsWith('/'));
public string LocalTempPath