9

I have a rendering that has a custom rendering parameters template. That rendering parameters template contains an image field. When I add the component to the page, add an image to the field, and try to save the page, I get the following error in the Sitecore log:

3200 13:40:13 ERROR After parsing a value an unexpected character was encountered: {. Path 'scLayout', line 1, position 2665.
Exception: Newtonsoft.Json.JsonReaderException
Message: After parsing a value an unexpected character was encountered: {. Path 'scLayout', line 1, position 2665.
Source: Newtonsoft.Json
   at Newtonsoft.Json.JsonTextReader.ParsePostValue()
   at Newtonsoft.Json.JsonTextReader.ReadInternal()
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Sitecore.ExperienceEditor.Speak.Server.Requests.PipelineProcessorRequest`1.Process(RequestArgs requestArgs)

When I debug I get the following error in Visual Studio:

System.Web.HttpRequestValidationException occurred
Message: Exception thrown: 'System.Web.HttpRequestValidationException' in System.Web.dll
Additional information: A potentially dangerous Request.Form value was detected from the client (data="...und Image=<image mediaid="{04D...").

This seems to suggest that my Rendering Parameter value is not getting properly encoded before posting back to Sitecore. Is there any way to resolve this?

This is occurring in Sitecore 8.2 Initial Release.

  • 1
    This seem like a sitecore Bug, Have you contacted Sitecore support? – Ahmed Okour Nov 2 '16 at 18:26
  • Yes, waiting on a reply. – Kevin Mazzoni Nov 2 '16 at 18:37
4

This has been acknowledged as a bug in this version of Sitecore (v8.2 Initial Release). The issue will occur for any field type, used in a Rendering Parameters template, whose value contains XML.

The solution provided by Sitecore Support is to update the postServerRequest function in the \sitecore\shell\client\Sitecore\ExperienceEditor\ExperienceEditor.js file.

Original Code

postServerRequest: function (requestType, commandContext, handler, async) {
    var token = $('input[name="__RequestVerificationToken"]').val();
    jQuery.ajax({
        url: "/-/speak/request/v1/expeditor/" + requestType,
        data: {
            __RequestVerificationToken: token,
            data: unescape(JSON.stringify(commandContext))
        },
        success: handler,
        type: "POST",
        async: async != undefined ? async : false
    });
}

Updated Code

postServerRequest: function (requestType, commandContext, handler, async) {
    var token = $('input[name="__RequestVerificationToken"]').val();

    var ajaxData = unescape(JSON.stringify(commandContext));
    if (commandContext && commandContext.scLayout){
        var obj = JSON.parse(commandContext.scLayout);
        if (obj && obj.r && obj.r.d && obj.r.d.forEach){
            obj.r.d.forEach(function(x,y){
                if (x.r && x.r.forEach) {
                    x.r.forEach(function(a,z){
                        var val = a["@par"];
                        if (val && val.length > 0){
                            ajaxData = ajaxData.replace(unescape(val), val);
                        }                       
                    });
                }
            });
        }
    }

    jQuery.ajax({
        url: "/-/speak/request/v1/expeditor/" + requestType,
        data: {
            __RequestVerificationToken: token,
            data: ajaxData
        },
        success: handler,
        type: "POST",
        async: async != undefined ? async : false
    });
}

The public reference number given to this bug report is 88222.

|improve this answer|||||
2

This is a known issue of Sitecore version 8.0 Update-6 (rev. 151127), version 8.0 Update-7 (rev. 160115), version 8.1 Update-1 (rev. 151207), and version 8.2 initial release (rev. 160729) where it fails to save items with a field of type "Rule editor". It seems you just found another case of that same bug. It makes me think that this bug affect all the fields that store XML in their raw value.

The problem was diagnosed and a workaround was provided in this StackOverflow question: https://stackoverflow.com/questions/35029713/save-return-error-in-sitecore-page-editor/35443212#35443212

|improve this answer|||||
  • I found this SO article. The error is similiar but best I can tell the suggested changes in the accepted answer have already made their way into v8.2. I'm not 100% because it seems the js files have had a fair amount of changes since the original issue was posted. – Kevin Mazzoni Nov 2 '16 at 20:30
2

There are additional issues found with Sitecore Versions 8.1 and 8.2 with regard to SPEAK UI and how markup langugage fields like rich text editors, image fields, and link fields store data that caused numerous issues.

Sitecore issued Public Reference #88491 which addresses various issues on Save action.

The following save actions are adjusted in the ExperienceEditor pipeline as part of the patch:

Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CheckItemLock Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CheckRevision Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.Validators Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.ValidateFields Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CheckBaseTemplateFieldChange Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CheckTemplateFieldChange Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CheckLinks Sitecore.Support.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CallServerSavePipeline

|improve this answer|||||
  • I can't find this reference number on Knowledge Base. Should I be looking somewhere else? – Kevin Mazzoni Nov 2 '16 at 20:28
  • I have yet to be able to find it on the KB site. It's only available by asking for it through Support. – Pete Navarra Nov 2 '16 at 20:32

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.