umbraco / Umbraco.Cloud.Issues

Public issue tracker for Umbraco Cloud
26 stars 2 forks source link

Deploy contrib - Nested content parsing error when there are square brackets surrounding the content of a textstring property #120

Closed HalldorLyngmo closed 4 years ago

HalldorLyngmo commented 5 years ago

Reproduction

Bug summary

I'm using nested content on a document type. There I've selected a document type which has a text string property.

So I create a node using the document type with the nested content and then fill out the textstring property with content like this: [something]. image

Save it and try to restore the content to the next env.

That fails like this: image

What I believe is happening is this. There is be a parsing issue as this is not valid json which is what they are expecting because of the square brackets.

An error occurred
The source environment has thrown a Umbraco.Deploy.Exceptions.ProcessArtifactException with message: 
Process pass #4 failed for artifact umb://document/584936aa2f3b4db183de6af24d274b4a. 
It might have been caused by an inner Newtonsoft.Json.JsonReaderException with message:
Unexpected character encountered while parsing value: S. Path '', line 1, position 1.

After attaching deploy contrib to the process I was able to get a bit more info. Deploy contrib is failing at line 232: Umbraco.Deploy.Contrib.Connectors.ValueConnectors.NestedContentValueConnector.SetValue(IContentBase content, String alias, String value) in C:\Git\Umbraco.Deploy.Contrib\src\Umbraco.Deploy.Contrib.Connectors\ValueConnectors\NestedContentValueConnector.cs:line 232

else

// test if the value is a json object (thus could be a nested complex editor)
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
JToken jtokenValue = convertedValue.ToString().DetectIsJson() ? JToken.Parse(convertedValue.ToString()) : null;
if (jtokenValue != null)
{
    row.PropertyValues[key] = jtokenValue;
}
else
{
    row.PropertyValues[key] = convertedValue;
}
}

Not sure what would be the best solution, but a validation of the input or a better error message when this happens would be good. Outputting "convertedValue.ToString()" in the error so you know where it fails f.ex.

Specifics

Umbraco version 7.14.0 assembly: 1.0.7009.26199 Umbraco.Deploy.Contrib - Release-v1.0.37

-- EXCEPTION ---------------------------------------------------
 (proper exception traces at the end of this log)
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: S. Path '', line 1, position 1.
Umbraco.Deploy.Exceptions.ProcessArtifactException: Process pass #4 failed for artifact umb://document/584936aa2f3b4db183de6af24d274b4a.
----------------------------------------------------------------

EXCEPTION:

Umbraco.Deploy.Exceptions.ProcessArtifactException: Process pass #4 failed for artifact umb://document/584936aa2f3b4db183de6af24d274b4a.
   at Umbraco.Deploy.Environments.LocalUmbracoEnvironment.ProcessArtifacts(IEnumerable`1 arts, IDeployContext context, CancellationToken token)
   at Umbraco.Deploy.Environments.LocalUmbracoEnvironment.ProcessPackageAsync(Guid sessionId, Package package, CancellationToken token)
   at Umbraco.Deploy.WorkItems.DeployRestoreWorkItemBase.<ProcessPackage>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Umbraco.Deploy.WorkItems.TargetPartialRestoreWorkItem.<Proceed>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Umbraco.Deploy.WorkItems.TargetPartialRestoreWorkItem.<ExecuteAsyncSub>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Umbraco.Deploy.WorkItems.TargetPartialRestoreWorkItem.<ExecuteAsyncSub>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Umbraco.Deploy.WorkItems.TargetPartialRestoreWorkItem.<ExecuteAsync>d__14.MoveNext()

INNER:
  Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: S. Path '', line 1, position 1.
     at Newtonsoft.Json.JsonTextReader.ParseValue()
     at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
     at Newtonsoft.Json.Linq.JArray.Load(JsonReader reader, JsonLoadSettings settings)
     at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
     at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
     at Umbraco.Deploy.Contrib.Connectors.ValueConnectors.NestedContentValueConnector.SetValue(IContentBase content, String alias, String value) in C:\Git\Umbraco.Deploy.Contrib\src\Umbraco.Deploy.Contrib.Connectors\ValueConnectors\NestedContentValueConnector.cs:line 232
     at Umbraco.Deploy.ServiceConnectors.ContentConnectorBase`2.MapProperties(TContent content, IEnumerable`1 propertyTypes, IDictionary`2 artProperties)
     at Umbraco.Deploy.ServiceConnectors.DocumentConnector.Process4(DeployState state, IDeployContext context, Int32 pass)
     at Umbraco.Deploy.Environments.LocalUmbracoEnvironment.ProcessArtifacts(IEnumerable`1 arts, IDeployContext context, CancellationToken token)

Steps to reproduce

  1. Cloud project with two environments, local and Live (Version 7)
  2. Use the Deploy contrib for value connectors
  3. Create a doc type with a text string property
  4. Create a doc type using nested content and select the previous doc type
  5. Create a node on Live using the nested content doc type. Insert content into the textstring property with square brackets around it - [something]
  6. Try to restore the node to Dev.

Expected result

The node should be there with the content

Actual result

An error message connected to parsing the nested content image


_This item has been added to our backlog AB#2627_

HalldorLyngmo commented 4 years ago

This one on was also happening on v8 with the Deploy.Contrib v3. There is another issue being fixed - https://github.com/umbraco/Umbraco.Deploy.Contrib/pull/40 - that changes the method at fault here.

I did some testing and after adding that fix the square brackets issue was gone for v8 and contrib v3. So logic dictates that when we backport the fix to contrib v2 this issue can be closed.

There is a PR for that here so I'll update this issue when it has been fully tested - https://github.com/umbraco/Umbraco.Deploy.Contrib/pull/41 -

HalldorLyngmo commented 4 years ago

Tested on v7 as well and there was no exception when transferring values with square brackets after applying the fix.

This will most likely be a part of the next release for the Deploy Contrib v2.

clausjensen commented 4 years ago

This was fixed in 3.0.1 of Deploy and backported to v7 - closing the issue here.

ronaldbarendse commented 4 years ago

This will most likely be a part of the next release for the Deploy Contrib v2.

This was fixed in 3.0.1 of Deploy and backported to v7 - closing the issue here.

This fix isn't merged/released for Umbraco 7 though, as https://github.com/umbraco/Umbraco.Deploy.Contrib/pull/41 is still open and the latest release is from 2019: https://www.nuget.org/packages/UmbracoDeploy.Contrib/2.0.0.