diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/MigrateDataTypeConfigurations.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/MigrateDataTypeConfigurations.cs index 9e428e5e65..f9542f7d47 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/MigrateDataTypeConfigurations.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/MigrateDataTypeConfigurations.cs @@ -86,6 +86,7 @@ public class MigrateDataTypeConfigurations : MigrationBase updated |= dataTypeDto.EditorAlias switch { PropertyEditorAliases.Boolean => HandleBoolean(ref configurationData), + PropertyEditorAliases.CheckBoxList => HandleCheckBoxList(ref configurationData), PropertyEditorAliases.ColorPicker => HandleColorPicker(ref configurationData), PropertyEditorAliases.ContentPicker => HandleContentPicker(ref configurationData), PropertyEditorAliases.DateTime => HandleDateTime(ref configurationData), @@ -126,6 +127,10 @@ public class MigrateDataTypeConfigurations : MigrationBase private bool HandleBoolean(ref Dictionary configurationData) => ReplaceIntegerStringWithBoolean(ref configurationData, "default"); + // translate "selectable items" from old "value list" format to string array + private bool HandleCheckBoxList(ref Dictionary configurationData) + => ReplaceValueListArrayWithStringArray(ref configurationData, "items"); + // translate "allowed colors" configuration from multiple old formats private bool HandleColorPicker(ref Dictionary configurationData) { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs index e481d3d89a..b8fd53be8a 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs @@ -19,25 +19,27 @@ public class ValueListUniqueValueValidator : IValueValidator public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { - var stringValue = value?.ToString(); - if (stringValue.IsNullOrWhiteSpace()) + if (value is null) { yield break; } - string[]? items = null; - try + var items = value as IEnumerable; + if (items is null) { - items = _configurationEditorJsonSerializer.Deserialize(stringValue); - } - catch - { - // swallow and report error below + try + { + items = _configurationEditorJsonSerializer.Deserialize(value.ToString() ?? string.Empty); + } + catch + { + // swallow and report error below + } } if (items is null) { - yield return new ValidationResult($"The configuration value {stringValue} is not a valid value list configuration", new[] { "items" }); + yield return new ValidationResult($"The configuration value {value} is not a valid value list configuration", ["items"]); yield break; } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs index 07a739d6da..8192afda99 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs @@ -73,4 +73,55 @@ public class EnsureUniqueValuesValidatorTest null); Assert.AreEqual(2, result.Count()); } + + [Test] + public void Handles_Null() + { + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); + var result = + validator.Validate( + null, + null, + null); + Assert.AreEqual(0, result.Count()); + } + + [Test] + public void Handles_IEnumerable_Of_String() + { + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); + IEnumerable value = new[] { "one", "two", "three" }; + var result = + validator.Validate( + value, + null, + null); + Assert.AreEqual(0, result.Count()); + } + + [Test] + public void Handles_Array_Of_String() + { + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); + string[] value = { "one", "two", "three" }; + var result = + validator.Validate( + value, + null, + null); + Assert.AreEqual(0, result.Count()); + } + + [Test] + public void Handles_List_Of_String() + { + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); + var value = new List { "one", "two", "three" }; + var result = + validator.Validate( + value, + null, + null); + Assert.AreEqual(0, result.Count()); + } }