aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-16 19:01:50 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-16 19:01:50 -0500
commit0346199c4ed5edb0d502f2e3f5972aafeea6c923 (patch)
treea53c7ffb35006f074695e8a2767935c5d755e633
parentaee67635e0c1048b890bc98812678086407d3b92 (diff)
downloadslskd-0346199c4ed5edb0d502f2e3f5972aafeea6c923.tar.gz
fix test
-rw-r--r--src/slskd/Common/Validation/StringAttribute.cs13
-rw-r--r--tests/slskd.Tests.Unit/Common/Validation/StringAttributeTests.cs7
2 files changed, 17 insertions, 3 deletions
diff --git a/src/slskd/Common/Validation/StringAttribute.cs b/src/slskd/Common/Validation/StringAttribute.cs
index 2fcf4283..bb323ba2 100644
--- a/src/slskd/Common/Validation/StringAttribute.cs
+++ b/src/slskd/Common/Validation/StringAttribute.cs
@@ -53,9 +53,16 @@ namespace slskd.Validation
{
var val = (string)value;
- if (!AllowNull && val is null)
+ if (val is null)
{
- return new ValidationResult($"The {validationContext.DisplayName} field must not be null");
+ if (!AllowNull)
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field must not be null");
+ }
+ else
+ {
+ return ValidationResult.Success;
+ }
}
if (!AllowEmpty && val is "")
@@ -64,7 +71,7 @@ namespace slskd.Validation
}
// check this after empty to avoid overlap
- if (!AllowWhiteSpace && string.IsNullOrWhiteSpace(val))
+ if (!AllowWhiteSpace && val.All(c => char.IsWhiteSpace(c)))
{
return new ValidationResult($"The {validationContext.DisplayName} field must not contain only whitespace");
}
diff --git a/tests/slskd.Tests.Unit/Common/Validation/StringAttributeTests.cs b/tests/slskd.Tests.Unit/Common/Validation/StringAttributeTests.cs
index dfa964f7..71e6ce8b 100644
--- a/tests/slskd.Tests.Unit/Common/Validation/StringAttributeTests.cs
+++ b/tests/slskd.Tests.Unit/Common/Validation/StringAttributeTests.cs
@@ -222,6 +222,13 @@ public class StringAttributeTests
=> StringAttributeTests.Validate(value, configure);
[Fact]
+ public void Null_Passes_When_AllowNull_Is_True()
+ {
+ var (isValid, _) = Validate(null);
+ Assert.True(isValid);
+ }
+
+ [Fact]
public void Null_Fails_When_AllowNull_Is_False()
{
var (isValid, _) = Validate(null, a => a.AllowNull = false);