8539: Allow alias in image cropper (#9266)
Co-authored-by: Owain Williams <owaingdwilliams@gmail.com>
This commit is contained in:
committed by
GitHub
parent
45de0a101e
commit
7f1d5fe7cc
@@ -22,7 +22,7 @@ namespace Umbraco.Core
|
||||
///</summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
|
||||
private const char DefaultEscapedStringEscapeChar = '\\';
|
||||
private static readonly char[] ToCSharpHexDigitLower = "0123456789abcdef".ToCharArray();
|
||||
private static readonly char[] ToCSharpEscapeChars;
|
||||
|
||||
@@ -1490,5 +1490,44 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
public static string NullOrWhiteSpaceAsNull(this string text)
|
||||
=> string.IsNullOrWhiteSpace(text) ? null : text;
|
||||
|
||||
/// <summary>
|
||||
/// Splits a string with an escape character that allows for the split character to exist in a string
|
||||
/// </summary>
|
||||
/// <param name="value">The string to split</param>
|
||||
/// <param name="splitChar">The character to split on</param>
|
||||
/// <param name="escapeChar">The character which can be used to escape the character to split on</param>
|
||||
/// <returns>The string split into substrings delimited by the split character</returns>
|
||||
public static IEnumerable<string> EscapedSplit(this string value, char splitChar, char escapeChar = DefaultEscapedStringEscapeChar)
|
||||
{
|
||||
if (value == null) yield break;
|
||||
|
||||
var sb = new StringBuilder(value.Length);
|
||||
var escaped = false;
|
||||
|
||||
foreach (var chr in value.ToCharArray())
|
||||
{
|
||||
if (escaped)
|
||||
{
|
||||
escaped = false;
|
||||
sb.Append(chr);
|
||||
}
|
||||
else if (chr == splitChar)
|
||||
{
|
||||
yield return sb.ToString();
|
||||
sb.Clear();
|
||||
}
|
||||
else if (chr == escapeChar)
|
||||
{
|
||||
escaped = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(chr);
|
||||
}
|
||||
}
|
||||
|
||||
yield return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,10 +252,10 @@ function umbRequestHelper($http, $q, notificationsService, eventsService, formHe
|
||||
//each item has a property alias and the file object, we'll ensure that the alias is suffixed to the key
|
||||
// so we know which property it belongs to on the server side
|
||||
var file = args.files[f];
|
||||
var fileKey = "file_" + file.alias + "_" + (file.culture ? file.culture : "") + "_" + (file.segment ? file.segment : "");
|
||||
var fileKey = "file_" + (file.alias || '').replace(/_/g, '\\_') + "_" + (file.culture ? file.culture.replace(/_/g, '\\_') : "") + "_" + (file.segment ? file.segment.replace(/_/g, '\\_') : "");
|
||||
|
||||
if (Utilities.isArray(file.metaData) && file.metaData.length > 0) {
|
||||
fileKey += ("_" + file.metaData.join("_"));
|
||||
fileKey += ("_" + _.map(file.metaData, x => ('' + x).replace(/_/g, '\\_')).join("_"));
|
||||
}
|
||||
formData.append(fileKey, file.file);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using Umbraco.Core;
|
||||
@@ -17,6 +21,8 @@ namespace Umbraco.Web.Editors.Binders
|
||||
/// </summary>
|
||||
internal static class ContentModelBinderHelper
|
||||
{
|
||||
private const char _escapeChar = '\\';
|
||||
|
||||
public static TModelSave BindModelFromMultipartRequest<TModelSave>(HttpActionContext actionContext, ModelBindingContext bindingContext)
|
||||
where TModelSave : IHaveUploadedFiles
|
||||
{
|
||||
@@ -30,6 +36,7 @@ namespace Umbraco.Web.Editors.Binders
|
||||
//The name that has been assigned in JS has 2 or more parts. The second part indicates the property id
|
||||
// for which the file belongs, the remaining parts are just metadata that can be used by the property editor.
|
||||
var parts = file.Headers.ContentDisposition.Name.Trim(Constants.CharArrays.DoubleQuote).Split(Constants.CharArrays.Underscore);
|
||||
|
||||
if (parts.Length < 2)
|
||||
{
|
||||
var response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest);
|
||||
|
||||
Reference in New Issue
Block a user