Update NestedContentPropertyEditor.cs to fix 2 bugs (#9236)
* Update NestedContentPropertyEditor.cs Make sure when trying to JsonConvert.DeserializeObject it is json... * Update NestedContentPropertyEditor.cs added null check
This commit is contained in:
@@ -363,7 +363,10 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString()))
|
||||
return new List<NestedContentRowValue>();
|
||||
|
||||
|
||||
if (!propertyValue.ToString().DetectIsJson())
|
||||
return new List<NestedContentRowValue>();
|
||||
|
||||
var rowValues = JsonConvert.DeserializeObject<List<NestedContentRowValue>>(propertyValue.ToString());
|
||||
|
||||
// There was a note here about checking if the result had zero items and if so it would return null, so we'll continue to do that
|
||||
@@ -388,23 +391,26 @@ namespace Umbraco.Web.PropertyEditors
|
||||
propertyTypes = contentTypePropertyTypes[contentType.Alias] = contentType.CompositionPropertyTypes.ToDictionary(x => x.Alias, x => x);
|
||||
|
||||
// find any keys that are not real property types and remove them
|
||||
foreach(var prop in row.RawPropertyValues.ToList())
|
||||
if (row.RawPropertyValues != null)
|
||||
{
|
||||
if (IsSystemPropertyKey(prop.Key)) continue;
|
||||
|
||||
// doesn't exist so remove it
|
||||
if (!propertyTypes.TryGetValue(prop.Key, out var propType))
|
||||
{
|
||||
row.RawPropertyValues.Remove(prop.Key);
|
||||
}
|
||||
else
|
||||
foreach (var prop in row.RawPropertyValues.ToList())
|
||||
{
|
||||
// set the value to include the resolved property type
|
||||
row.PropertyValues[prop.Key] = new NestedContentPropertyValue
|
||||
if (IsSystemPropertyKey(prop.Key)) continue;
|
||||
|
||||
// doesn't exist so remove it
|
||||
if (!propertyTypes.TryGetValue(prop.Key, out var propType))
|
||||
{
|
||||
PropertyType = propType,
|
||||
Value = prop.Value
|
||||
};
|
||||
row.RawPropertyValues.Remove(prop.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the value to include the resolved property type
|
||||
row.PropertyValues[prop.Key] = new NestedContentPropertyValue
|
||||
{
|
||||
PropertyType = propType,
|
||||
Value = prop.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user