V10: Fix to allow dragged images in the rich text editor to be correctly uploaded (#13016)

* update string extensions IsFullPath to support more filepaths with new built-in Path.IsPathFullyQualified

* resolve TODO to switch to Path.IsPathFullyQualified supported from .NET Standard 2.1

* Use content root instead of web root for uploaded images

* Un-break a breaking change

* handle special parsing of AngularJS json response

* change htmlId selector to support html id's with numbers

* remove bad test case

* test IsFullPath without tricky UNC paths that are not useful

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
(cherry picked from commit d18dc92137)
This commit is contained in:
Jacob Overgaard
2022-09-19 10:29:12 +02:00
committed by Sebastiaan Janssen
parent 963d0018c2
commit 1fe4c5169c
8 changed files with 91 additions and 61 deletions

View File

@@ -45,7 +45,7 @@ public class TinyMceController : UmbracoAuthorizedApiController
{
// Create an unique folder path to help with concurrent users to avoid filename clash
var imageTempPath =
_hostingEnvironment.MapPathWebRoot(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid());
_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid());
// Ensure image temp path exists
if (Directory.Exists(imageTempPath) == false)
@@ -81,7 +81,7 @@ public class TinyMceController : UmbracoAuthorizedApiController
}
var newFilePath = imageTempPath + Path.DirectorySeparatorChar + safeFileName;
var relativeNewFilePath = _ioHelper.GetRelativePath(newFilePath);
var relativeNewFilePath = GetRelativePath(newFilePath);
await using (FileStream stream = System.IO.File.Create(newFilePath))
{
@@ -90,4 +90,17 @@ public class TinyMceController : UmbracoAuthorizedApiController
return Ok(new { tmpLocation = relativeNewFilePath });
}
// Use private method istead of _ioHelper.GetRelativePath as that is relative for the webroot and not the content root.
private string GetRelativePath(string path)
{
if (path.IsFullPath())
{
var rootDirectory = _hostingEnvironment.MapPathContentRoot("~");
var relativePath = _ioHelper.PathStartsWith(path, rootDirectory) ? path[rootDirectory.Length..] : path;
path = relativePath;
}
return PathUtility.EnsurePathIsApplicationRootPrefixed(path);
}
}