Skip to content

Commit

Permalink
Fixed issue with TryConvertValueToCrlType method incorrectly enclosin…
Browse files Browse the repository at this point in the history
…g string values in double quotes
  • Loading branch information
abjerner authored and nul800sebastiaan committed Mar 16, 2022
1 parent ce81755 commit 76ecb29
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Umbraco.Core/PropertyEditors/DataValueEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,25 @@ public IEnumerable<ValidationResult> Validate(object value, bool required, strin
/// <returns></returns>
internal Attempt<object> TryConvertValueToCrlType(object value)
{
if (value is JToken jsonValue)
if (value is JValue jsonValue)
{
if (jsonValue is JContainer && jsonValue.HasValues == false)
// Calling the "ToString(Formatting)" method on a string value results in a new
// string enclosed in double quotes (which we don't want), as the method is declared
// in the JToken class. Calling either of the "ToString()" or "ToString(CultureInfo)"
// methods hits the overridden methods in the JValue class, which correctly doesn't
// enclose the value in double quotes.
value = jsonValue.ToString(CultureInfo.InvariantCulture);
}
else if (value is JToken jsonToken)
{
if (jsonToken is JContainer && jsonToken.HasValues == false)
{
// Empty JSON array/object
value = null;
}
else
{
value = jsonValue.ToString(Formatting.None);
value = jsonToken.ToString(Formatting.None);
}
}

Expand Down

0 comments on commit 76ecb29

Please sign in to comment.