Fixes U4-1746 Duplicate image source (src) when inserting resized image in tiny
mce (richtext editor)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -14,7 +15,12 @@ namespace umbraco.editorControls.tinymce
|
||||
{
|
||||
public static string cleanImages(string html)
|
||||
{
|
||||
var allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(',');
|
||||
var allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(',').ToList();
|
||||
|
||||
//Always add src as it's essential to output any image at all
|
||||
if (allowedAttributes.Contains("src") == false)
|
||||
allowedAttributes.Add("src");
|
||||
|
||||
const string pattern = @"<img [^>]*>";
|
||||
var tags = Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
@@ -43,7 +49,11 @@ namespace umbraco.editorControls.tinymce
|
||||
{
|
||||
int newWidth;
|
||||
int newHeight;
|
||||
cleanTag += DoResize(ht, out newWidth, out newHeight);
|
||||
string newSrc;
|
||||
|
||||
cleanTag += DoResize(ht, out newWidth, out newHeight, out newSrc);
|
||||
|
||||
ht["src"] = newSrc;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
@@ -96,7 +106,7 @@ namespace umbraco.editorControls.tinymce
|
||||
return html;
|
||||
}
|
||||
|
||||
private static string DoResize(IDictionary attributes, out int finalWidth, out int finalHeight)
|
||||
private static string DoResize(IDictionary attributes, out int finalWidth, out int finalHeight, out string newSrc)
|
||||
{
|
||||
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
var orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " "));
|
||||
@@ -106,7 +116,7 @@ namespace umbraco.editorControls.tinymce
|
||||
var newWidth = int.Parse(helper.FindAttribute(attributes, "width"));
|
||||
var newHeight = int.Parse(helper.FindAttribute(attributes, "height"));
|
||||
|
||||
var newSrc = "";
|
||||
newSrc = "";
|
||||
|
||||
if (orgHeight > 0 && orgWidth > 0 && orgSrc != "")
|
||||
{
|
||||
@@ -131,7 +141,7 @@ namespace umbraco.editorControls.tinymce
|
||||
finalWidth = newWidth;
|
||||
finalHeight = newHeight;
|
||||
|
||||
return " src=\"" + newSrc + "\" width=\"" + newWidth + "\" height=\"" + newHeight + "\"";
|
||||
return " width=\"" + newWidth + "\" height=\"" + newHeight + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user