diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-08-14 12:35:38 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-08-14 12:35:38 -0500 |
| commit | 75b5941b580ee9c68ea16d58c44ac5f15c524c03 (patch) | |
| tree | 399d9f0f328a9ff6c337cce88fa2092c5a8d6599 /src | |
| parent | cd2b93fb8c75ca41fd31126bf41dadf9c1668400 (diff) | |
| download | slskd-75b5941b580ee9c68ea16d58c44ac5f15c524c03.tar.gz | |
validate share aliases
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Options.cs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index bf83e74f..63054b89 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -24,6 +24,8 @@ namespace slskd using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Diagnostics; + using System.Linq; + using System.Text.RegularExpressions; using FluentFTP; using slskd.Configuration; using slskd.Validation; @@ -219,7 +221,7 @@ namespace slskd /// <summary> /// Directory options. /// </summary> - public class DirectoriesOptions + public class DirectoriesOptions : IValidatableObject { /// <summary> /// Gets the path where application data is saved. @@ -258,6 +260,33 @@ namespace slskd [EnvironmentVariable("SHARED_DIR")] [Description("path to shared files")] public string[] Shared { get; private set; } = new[] { Program.DefaultSharedDirectory }; + + /// <summary> + /// Extended validation. + /// </summary> + /// <param name="validationContext"></param> + /// <returns></returns> + public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) + { + var results = new List<ValidationResult>(); + + foreach (var share in Shared) + { + var matches = Regex.Matches(share, @"^(-?)\[(.*)\](.*)$"); + + if (matches.Any()) + { + var alias = matches[0].Groups[2].Value; + + if (alias.Contains('\\') || alias.Contains('/')) + { + results.Add(new ValidationResult($"Share {share} is invalid; aliases may not contain path separators '/' or '\'")); + } + } + } + + return results; + } } /// <summary> |
