From f95b347191854e8057c8086e52165a83e2fa8a7d Mon Sep 17 00:00:00 2001 From: whoswhip Date: Sun, 1 Feb 2026 20:12:59 -0500 Subject: [PATCH] fix: ensure length > 0 and that arrays have value before validating --- SharpbinV3.Server/DTOs/User/RegisterUserDto.cs | 2 +- SharpbinV3.Server/DTOs/User/UpdateUserDto.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs b/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs index 3530c96..8590ded 100644 --- a/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs +++ b/SharpbinV3.Server/DTOs/User/RegisterUserDto.cs @@ -26,7 +26,7 @@ namespace SharpbinV3.Server.DTOs if (!ValidatePassword().IsMatch(Password)) results.Add(new ValidationResult("Password should have at least 8 characters, including uppercase, lowercase, and digits.", [nameof(Password)])); - if (DisplayName != null) + if (DisplayName != null && DisplayName.Length > 0) { if (DisplayName.Length < 3 || DisplayName.Length > 26) results.Add(new ValidationResult("DisplayName must be between 3 and 26 characters.", [nameof(DisplayName)])); diff --git a/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs b/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs index 2c4b785..fad6897 100644 --- a/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs +++ b/SharpbinV3.Server/DTOs/User/UpdateUserDto.cs @@ -14,25 +14,25 @@ namespace SharpbinV3.Server.DTOs public IEnumerable Validate(ValidationContext validationContext) { var results = new List(); - if (DisplayName != null) + if (DisplayName != null && DisplayName.Length > 0) { if (DisplayName.Length < 3 || DisplayName.Length > 26) results.Add(new ValidationResult("DisplayName must be between 3 and 26 characters.", [nameof(DisplayName)])); if (!ValidateDisplayname().IsMatch(DisplayName)) results.Add(new ValidationResult("DisplayName can only contain alphanumeric characters, underscores, periods, and spaces (no leading or trailing spaces).", [nameof(DisplayName)])); } - if (Email != null) + if (Email != null && Email.Length > 0) { var emailAttribute = new EmailAddressAttribute(); if (!emailAttribute.IsValid(Email)) results.Add(new ValidationResult("Invalid email format.", [nameof(Email)])); } - if (Visibility != null) + if (Visibility != null && Visibility.HasValue) { if (Visibility < 0 || Visibility > 2) results.Add(new ValidationResult("Visibility must be between 0 and 2.", [nameof(Visibility)])); } - if (Roles != null) + if (Roles != null && Roles.Length > 0) { if (Roles.Length == 0) results.Add(new ValidationResult("Roles cannot be an empty array.", [nameof(Roles)]));