Problem
In our Sitecore 8 solution, content authors used to add encoded values for html tags like etc. in Multi-line text field and it worked correctly. When the solution was upgraded to Sitecore 10, all the html tags in multi-line text field started to get rendered as plain text instead of html as in snapshot below -
Solution
RENDERING - HTML ENCODED FIELD TYPES
This setting specifies a pipe-separated list of field types that should be HTML encoded when rendered by the <renderField> pipeline.
Default value: text|single-line text|multi-line text
We found that this setting has multi-line text included now which wasnt the case in Sitecore 8 -
<setting name="Rendering.HtmlEncodedFieldTypes" value="text|single-line text|multi-line text" />
To fix this, we removed multi-line text from the value of this setting using below patch -
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:environment="http://www.sitecore.net/xmlconfig/environment/">
<sitecore>
<mvc environment:require="Dev or Qa or Prod">
<precompilation>
<assemblies>
<assemblyIdentity name="MySite.Foundation.Common" />
</assemblies>
</precompilation>
</mvc>
<settings>
<setting name="Rendering.HtmlEncodedFieldTypes">
<patch:attribute name="value">text|single-line text</patch:attribute>
</setting>
</settings>
</sitecore>
</configuration>
But this was not enough to fix the issue.
Updating the above patch introduced a new issue. Now, if multi-line text field has any html in it, it renders no values as if the field was empty.
On investigating it deeper, a processor Sitecore.ExperienceEditor.Pipelines.RenderField.EncodeTextFieldValue was found which sort of hardcoded that if field is single-line text or multi-line text, always remove the scripts from it using method RemoveScript(). Here is the code -
public class EncodeTextFieldValue
{
public void Process(RenderFieldArgs args)
{
Assert.ArgumentNotNull((object)args, nameof(args));
string fieldTypeKey = args.FieldTypeKey;
if (Settings.Rendering.HtmlEncodedFieldTypes.Contains(args.FieldTypeKey) || (!fieldTypeKey.Equals("single-line text", StringComparison.InvariantCulture) && !fieldTypeKey.Equals("multi-line text", StringComparison.InvariantCulture)))
{
return;
}
if (Context.PageMode.IsPreview || Context.PageMode.IsNormal)
{
args.Result.FirstPart = EncodeTextFieldValue.RemoveScripts(HttpUtility.HtmlDecode(args.Result.FirstPart));
}
else
{
args.Result.FirstPart = HttpUtility.HtmlEncode(EncodeTextFieldValue.RemoveScripts(args.Result.FirstPart));
}
}
protected static string RemoveScripts(string content)
{
string str = String.Empty;
if (Settings.HtmlEditor.RemoveScripts)
{
str = WebUtil.RemoveAllScripts(content);
}
return str;
}
This pipeline didnt exist in Sitecore 8 dlls. Its something new I saw in Sitecore 10 dlls and might have been introduced in Sitecore 9 dlls as well.
This method was written in such way that if Settings.HtmlEditor.RemoveScripts setting is set to false, it will return an empty string. By default, Settings.HtmlEditor.RemoveScripts is true in Sitecore 10. In our case, this value was overridden by a module we were using for video players. So, we wrote a custom processor which inherited code from original Sitecore.ExperienceEditor.Pipelines.RenderField.EncodeTextFieldValue processor and customized the Remove Scripts() method to -
protected static string RemoveScriptsCustom(string content)
{
string str = content;
if (Settings.HtmlEditor.RemoveScripts)
{
str = WebUtil.RemoveAllScripts(content);
}
return str;
}
Once we implemented this in our custom processor, our multiline text field started working as expected.
I hope you find this information useful. Thanks!