diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-11-08 10:15:14 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-08 10:15:14 -0600 |
| commit | 169bb8a3c0098599a617d8553e93c694bd813795 (patch) | |
| tree | 4d825302717fc76d543b6a24469ad23a605cd5c8 /src/slskd/Common/Validation | |
| parent | 4eaa2b13e2da250d7b89073a15e9f1e077661fd7 (diff) | |
| parent | cefdcd02e28b1f02f546002fdd475de4fa03e839 (diff) | |
| download | slskd-169bb8a3c0098599a617d8553e93c694bd813795.tar.gz | |
Merge branch 'master' into dependabot/npm_and_yarn/src/web/follow-redirects-1.16.2
Diffstat (limited to 'src/slskd/Common/Validation')
| -rw-r--r-- | src/slskd/Common/Validation/EnumAttribute.cs | 4 | ||||
| -rw-r--r-- | src/slskd/Common/Validation/FileExistsAttribute.cs | 3 | ||||
| -rw-r--r-- | src/slskd/Common/Validation/StringAttribute.cs | 2 |
3 files changed, 5 insertions, 4 deletions
diff --git a/src/slskd/Common/Validation/EnumAttribute.cs b/src/slskd/Common/Validation/EnumAttribute.cs index fc077bb6..cdbaccda 100644 --- a/src/slskd/Common/Validation/EnumAttribute.cs +++ b/src/slskd/Common/Validation/EnumAttribute.cs @@ -60,14 +60,14 @@ namespace slskd.Validation return new ValidationResult($"The {validationContext.DisplayName} field contains one or more null or empty values"); } - if (array.Any(x => !Enum.TryParse(TargetType, x, IgnoreCase, out _))) + if (array.Any(x => !Enum.TryParse(TargetType, x, IgnoreCase, out var parsed) || !Enum.IsDefined(TargetType, parsed))) { return new ValidationResult($"The elements in the {validationContext.DisplayName} field must all be one of: {string.Join(", ", Enum.GetNames(TargetType))}. Case {(IgnoreCase ? "insensitive" : "sensitive")}."); } } else { - if (value != null && !Enum.TryParse(TargetType, value.ToString(), IgnoreCase, out _)) + if (value != null && (!Enum.TryParse(TargetType, value.ToString(), IgnoreCase, out var parsed) || !Enum.IsDefined(TargetType, parsed))) { return new ValidationResult($"The {validationContext.DisplayName} field must be one of: {string.Join(", ", Enum.GetNames(TargetType))}. Case {(IgnoreCase ? "insensitive" : "sensitive")}."); } diff --git a/src/slskd/Common/Validation/FileExistsAttribute.cs b/src/slskd/Common/Validation/FileExistsAttribute.cs index c4d97a7c..6fc50f63 100644 --- a/src/slskd/Common/Validation/FileExistsAttribute.cs +++ b/src/slskd/Common/Validation/FileExistsAttribute.cs @@ -32,6 +32,7 @@ namespace slskd.Validation { + using System; using System.ComponentModel.DataAnnotations; using System.IO; @@ -71,7 +72,7 @@ namespace slskd.Validation using var fs = File.Open(file, FileMode.Open, FileAccess.Value); fs.Close(); } - catch (IOException) + catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException) { return new ValidationResult($"The {validationContext.DisplayName} field specifies a file '{file}' that cannot be opened for required access '{FileAccess}'"); } diff --git a/src/slskd/Common/Validation/StringAttribute.cs b/src/slskd/Common/Validation/StringAttribute.cs index bb323ba2..d656a047 100644 --- a/src/slskd/Common/Validation/StringAttribute.cs +++ b/src/slskd/Common/Validation/StringAttribute.cs @@ -90,7 +90,7 @@ namespace slskd.Validation if (Pattern is not null && Pattern.IsMatch(val)) { - return new ValidationResult($"The {validationContext.DisplayName} field must match the regular expression {Pattern.ToJson()}"); + return new ValidationResult($"The {validationContext.DisplayName} field must not match the regular expression {Pattern.ToJson()}"); } return ValidationResult.Success; |
