aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Validation/RelativePathAttribute.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-06-07 14:45:04 -0500
committerGitHub <noreply@github.com>2026-06-07 14:45:04 -0500
commitb747b68ba0ba777be578e73bd1328fbde940e436 (patch)
tree160d23aeb8707dc04f81bb52e81913c1b77bb2a4 /src/slskd/Common/Validation/RelativePathAttribute.cs
parente06999e5eec1616d93b34ffbab0eade617d1aaf6 (diff)
parent2d069bbf1f71f38e1286e27d45c24b478feb11ac (diff)
downloadslskd-b747b68ba0ba777be578e73bd1328fbde940e436.tar.gz
Merge branch 'master' into dependabot/npm_and_yarn/src/web/launch-editor-2.14.1
Diffstat (limited to 'src/slskd/Common/Validation/RelativePathAttribute.cs')
-rw-r--r--src/slskd/Common/Validation/RelativePathAttribute.cs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/slskd/Common/Validation/RelativePathAttribute.cs b/src/slskd/Common/Validation/RelativePathAttribute.cs
index f465ba98..ea2b627b 100644
--- a/src/slskd/Common/Validation/RelativePathAttribute.cs
+++ b/src/slskd/Common/Validation/RelativePathAttribute.cs
@@ -33,36 +33,50 @@
namespace slskd.Validation
{
using System.ComponentModel.DataAnnotations;
- using System.Runtime.InteropServices;
/// <summary>
/// Validates that the specified path is relative.
/// </summary>
public class RelativePathAttribute : ValidationAttribute
{
- public RelativePathAttribute()
+ public RelativePathAttribute(OperatingSystem os = OperatingSystem.Current)
{
- }
+ if (os != OperatingSystem.Current && os != OperatingSystem.Any && os != OperatingSystem.All)
+ {
+ throw new System.ArgumentException("OperatingSystem argument for RelativePathAttribute must be one of: Current, Any, All", nameof(os));
+ }
- public RelativePathAttribute(OSPlatform? os = null)
- {
OS = os;
}
- public OSPlatform? OS { get; }
+ public OperatingSystem OS { get; }
+
+ private OperatingSystem? Injected { get; }
+
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null && value is string str && !string.IsNullOrEmpty(str))
{
var path = value.ToString();
- if (!FileSafety.IsPathRelative(path, os: OS))
+ if (OS == OperatingSystem.Current)
+ {
+ if (!FileSafety.IsPathRelative(path, os: Injected ?? Compute.OperatingSystem()))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field must be a relative path on the current operating system.");
+ }
+
+ return ValidationResult.Success;
+ }
+
+ // OS == OperatingSystem.All or .Any;
+ if (!FileSafety.IsPathRelative(path, os: OperatingSystem.Linux) || !FileSafety.IsPathRelative(path, os: OperatingSystem.Windows))
{
- return new ValidationResult($"The {validationContext.DisplayName} field must be a relative path.");
+ return new ValidationResult($"The {validationContext.DisplayName} field must be a relative path on all operating systems.");
}
}
return ValidationResult.Success;
}
}
-}
+} \ No newline at end of file