diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-13 19:44:54 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-13 19:44:54 -0500 |
| commit | dc1e6a63db9ff87813633963b2f3d7acc60d2709 (patch) | |
| tree | c420b2a5d3d51fc0858eb7905d5937a3ee3731d3 /src | |
| parent | dddcc1314d2260a21fe62e61b92f446a15357b04 (diff) | |
| parent | aada6016541b8a1d0d397052daa9b6c40f8a4277 (diff) | |
| download | slskd-dc1e6a63db9ff87813633963b2f3d7acc60d2709.tar.gz | |
Merge pull request #694 from pn04/dir-relative-validation
added a DirectoryIsRelative validation attribute
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs | 38 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs b/src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs new file mode 100644 index 00000000..e4e13bc8 --- /dev/null +++ b/src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs @@ -0,0 +1,38 @@ +// <copyright file="DirectoryIsRelativeAttribute.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Validation +{ + using System.ComponentModel.DataAnnotations; + using System.IO; + + /// <summary> + /// Validates that the specified path is relative. + /// </summary> + public class DirectoryIsRelativeAttribute : ValidationAttribute + { + protected override ValidationResult IsValid(object value, ValidationContext validationContext) + { + if (Path.IsPathRooted(value?.ToString())) + { + return new ValidationResult($"The {validationContext.DisplayName} field specifies a non-realtive directory path: '{value}'."); + } + + return ValidationResult.Success; + } + } +}
\ No newline at end of file diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 4c146d32..484a514b 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1167,6 +1167,7 @@ namespace slskd [Description("path to static web content")] [StringLength(255, MinimumLength = 1)] [DirectoryExists] + [DirectoryIsRelative] [RequiresRestart] public string ContentPath { get; init; } = "wwwroot"; |
