aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-14 08:57:18 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-14 08:57:18 -0500
commit4d69426a19ffff519368ec2b75e8634fdd23d861 (patch)
treed2de40606e3c3fa901effe2d543adb20974b93c4 /src/slskd/Common
parentb56a6650e95b3964d22d0af8c4c44b74d2800c29 (diff)
parent593308d4e786cd569e3a683f5b02b8f13aa39b23 (diff)
downloadslskd-4d69426a19ffff519368ec2b75e8634fdd23d861.tar.gz
Merge remote-tracking branch 'origin/master' into agent
Diffstat (limited to 'src/slskd/Common')
-rw-r--r--src/slskd/Common/ChannelReader.cs2
-rw-r--r--src/slskd/Common/CommonExtensions.cs2
-rw-r--r--src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs38
3 files changed, 40 insertions, 2 deletions
diff --git a/src/slskd/Common/ChannelReader.cs b/src/slskd/Common/ChannelReader.cs
index 49ebf0cf..a5386715 100644
--- a/src/slskd/Common/ChannelReader.cs
+++ b/src/slskd/Common/ChannelReader.cs
@@ -50,7 +50,7 @@ namespace slskd.Shares
public class ChannelReader<T> : IChannelReader
{
/// <summary>
- /// Initializes a new instance of the <see cref="ChannelReader"/> class.
+ /// Initializes a new instance of the <see cref="ChannelReader{T}"/> class.
/// </summary>
/// <param name="channel">The channel from which the reader will read.</param>
/// <param name="handler">An <see cref="Action"/> to be invoked for each item read from the channel.</param>
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 307e1469..561162d4 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -346,7 +346,7 @@ namespace slskd
/// </summary>
/// <typeparam name="T">The Enum type to which to cast.</typeparam>
/// <param name="str">The string to cast.</param>
- /// <returns>The cast enum</returns>
+ /// <returns>The cast enum.</returns>
public static T ToEnum<T>(this string str)
{
return (T)Enum.Parse(typeof(T), str, ignoreCase: true);
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