7

Using sitecore 8.1 update -1

When adding a description that includes & (e.g. hola & hello) to a GeneralLink field, the error below is thrown and the value is not shown on either content editor or content tree. The issue is that CE is not translating & to & -confirmed by checking raw values.

However, if I add the value using content tree, it saves & but doesn't show using normal view and will break again if any changes are made using content tree. I heard this was fixed in 8.2 but can't find the fix.

Error:

13684 10:45:48 ERROR First 200 characters: 13684 10:45:48 ERROR Call stack: at Sitecore.MainUtil.GetCallStack() at Sitecore.Xml.XmlUtil.LoadXml(String xml) at Sitecore.Shell.Applications.ContentEditor.Link.SetValue() at Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderField(Control parent, Field field, Item fieldType, Boolean readOnly, String value) at Sitecore.Shell.Applications.ContentEditor.EditorFormatter.RenderField(Control parent, Field field, Item fieldType, Boolean readOnly) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderInput(Field field) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderElement(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderChildElements(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderMarker(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderElement(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderChildElements(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderSectionPanel(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderElement(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.AddText(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderElement(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.AddText(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.RenderElement(XmlNode element) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.Render(XmlDocument skin) at Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor.Process(RenderContentEditorArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Shell.Applications.ContentManager.Editor.Render(RenderContentEditorArgs args, Control parent) at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.RenderEditor(Item item, Item root, Control parent, Boolean showEditor) at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.UpdateEditor(Item folder, Item root, Boolean showEditor) at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.Update() at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.OnPreRendered(EventArgs e) at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj) at Sitecore.Shell.Applications.ContentManager.ContentEditorPage.OnPreRender(EventArgs e) at System.Web.UI.Control.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

13

This is a known bug. I've seen it fixed in the 8.2 release notes.

https://dev.sitecore.net/Downloads/Sitecore%20Experience%20Platform/82/Sitecore%20Experience%20Platform%2082%20Initial%20Release/Release%20Notes - reference 82835.

Unfortunately, I've not seen any workarounds for your release. I suggest you get in touch with Sitecore support.

Eventually, I assume, the above fix will be rolled into an 8.1 update release.

9

For those who can't upgrade to 8.2, sitecore support has provided a solution. I'll post the code here as I don't know a better way of sharing the library.

As a reference Ticket number: 471609 | Sitecore Support - Bug #109428

Code provided contains 2 classes and a javascript change.

  1. LinkRenderer.cs overrides default RenderFieldResult method
  2. GetLinkFieldValue.cs calls method in LinkRenderer.cs
  3. \sitecore\shell\client\Sitecore\ExperienceEditor\ExperienceEditor.js amends method postServerRequest to encode string.

LinkRenderer.cs

public class LinkRenderer : Sitecore.Xml.Xsl.LinkRenderer
{
    private readonly char[] _delimiter;

    public LinkRenderer(Item item) : base(item)
    {
        this._delimiter = new char[]
        {
            '=',
            '&'
        };
    }

    public override RenderFieldResult Render()
    {
        SafeDictionary<string> safeDictionary = new SafeDictionary<string>();
        safeDictionary.AddRange(base.Parameters);
        if (MainUtil.GetBool(safeDictionary["endlink"], false))
        {
            return RenderFieldResult.EndLink;
        }
        Set<string> set = Set<string>.Create(new string[]
        {
            "field",
            "select",
            "text",
            "haschildren",
            "before",
            "after",
            "enclosingtag",
            "fieldname",
            "disable-web-editing"
        });
        LinkField linkField = base.LinkField;
        if (linkField != null)
        {
            safeDictionary["title"] = HttpUtility.HtmlAttributeEncode(StringUtil.GetString(new string[]
            {
                safeDictionary["title"],
                linkField.Title
            }));
            safeDictionary["target"] = StringUtil.GetString(new string[]
            {
                safeDictionary["target"],
                linkField.Target
            });
            safeDictionary["class"] = StringUtil.GetString(new string[]
            {
                safeDictionary["class"],
                linkField.Class
            });
        }
        string text = string.Empty;
        string rawParameters = base.RawParameters;
        if (!string.IsNullOrEmpty(rawParameters) && rawParameters.IndexOfAny(this._delimiter) < 0)
        {
            text = rawParameters;
        }
        if (string.IsNullOrEmpty(text))
        {
            Item targetItem = base.TargetItem;
            string text2 = (targetItem != null) ? targetItem.DisplayName : string.Empty;
            string text3 = (linkField != null) ? linkField.Text : string.Empty;
            text = HttpUtility.HtmlAttributeEncode(StringUtil.GetString(new string[]
            {
                text,
                safeDictionary["text"],
                text3,
                text2
            }));
        }
        string url = this.GetUrl(linkField);
        string linkType;
        if ((linkType = base.LinkType) != null && linkType == "javascript")
        {
            safeDictionary["href"] = "#";
            safeDictionary["onclick"] = StringUtil.GetString(new string[]
            {
                safeDictionary["onclick"],
                url
            });
        }
        else
        {
            safeDictionary["href"] = HttpUtility.HtmlEncode(StringUtil.GetString(new string[]
            {
                safeDictionary["href"],
                url
            }));
        }
        StringBuilder stringBuilder = new StringBuilder("<a", 47);
        foreach (KeyValuePair<string, string> current in safeDictionary)
        {
            string key = current.Key;
            string value = current.Value;
            if (!set.Contains(key.ToLowerInvariant()))
            {
                FieldRendererBase.AddAttribute(stringBuilder, key, value);
            }
        }
        stringBuilder.Append('>');
        if (!MainUtil.GetBool(safeDictionary["haschildren"], false))
        {
            if (string.IsNullOrEmpty(text))
            {
                return RenderFieldResult.Empty;
            }
            stringBuilder.Append(text);
        }
        return new RenderFieldResult
        {
            FirstPart = stringBuilder.ToString(),
            LastPart = "</a>"
        };
    }
}

GetLinkFieldValue.cs

public class GetLinkFieldValue : Sitecore.Pipelines.RenderField.GetLinkFieldValue
{
    protected override Sitecore.Xml.Xsl.LinkRenderer CreateRenderer(Item item)
    {
        return new Sitecore.Support.Xml.Xsl.LinkRenderer(item);
    }
}

sitecore\shell\client\Sitecore\ExperienceEditor\ExperienceEditor.js

postServerRequest: function (requestType, commandContext, handler, async) {
  var token = $('input[name="__RequestVerificationToken"]').val();
  jQuery.ajax({
    url: "/-/speak/request/v1/expeditor/" + requestType,
    data: {
      __RequestVerificationToken: token,
      /*Sitecore Support - Bug #109428*/
      data: jQuery("<div/>").text(decodeURIComponent(JSON.stringify(commandContext))).html()
    },
    success: handler,
    type: "POST",
    async: async != undefined ? async : false
  });
}

Config patch

<sitecore>    
  <pipelines>
    <renderField>
      <processor type="Sitecore.Support.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Support.109420" patch:instead="*[@type='Sitecore.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Kernel']"/>
    </renderField>
  </pipelines>
</sitecore>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.