Skip to content

Commit 0d79a1f

Browse files
authored
Fixed issue with max validation using default 0 value. (#18616)
1 parent cb78e52 commit 0d79a1f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Umbraco.Infrastructure/PropertyEditors/SliderPropertyEditor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Umbraco.Cms.Core.Models.Editors;
1111
using Umbraco.Cms.Core.Models.Validation;
1212
using Umbraco.Cms.Core.PropertyEditors.Validation;
13-
using Umbraco.Cms.Core.PropertyEditors.Validators;
1413
using Umbraco.Cms.Core.Serialization;
1514
using Umbraco.Cms.Core.Services;
1615
using Umbraco.Cms.Core.Strings;
@@ -261,7 +260,7 @@ public IEnumerable<ValidationResult> Validate(object? value, string? valueType,
261260
["value"]);
262261
}
263262

264-
if (sliderRange.To > sliderConfiguration.MaximumValue)
263+
if (sliderConfiguration.MaximumValue != 0 && sliderRange.To > sliderConfiguration.MaximumValue)
265264
{
266265
yield return new ValidationResult(
267266
LocalizedTextService.Localize("validation", "outOfRangeMaximum", [sliderRange.To.ToString(), sliderConfiguration.MaximumValue.ToString()]),

tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/SliderValueEditorTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ public void Validates_Is_Less_Than_Or_Equal_To_Configured_Max(decimal from, deci
205205
}
206206
}
207207

208+
[Test]
209+
public void Max_Item_Validation_Respects_0_As_Unlimited()
210+
{
211+
var value = new JsonObject
212+
{
213+
{ "from", 1.0m },
214+
{ "to", 1.0m },
215+
};
216+
var editor = CreateValueEditor();
217+
editor.ConfigurationObject = new SliderConfiguration();
218+
219+
var result = editor.Validate(value, false, null, PropertyValidationContext.Empty());
220+
Assert.IsEmpty(result);
221+
}
222+
208223
[TestCase(0.2, 1.3, 1.7, true)]
209224
[TestCase(0.2, 1.4, 1.7, false)]
210225
[TestCase(0.2, 1.3, 1.6, false)]

0 commit comments

Comments
 (0)