From 2a2ac5402cf683ccf04068fdf3f4e0bd4024862d Mon Sep 17 00:00:00 2001 From: Darcy Abell Date: Mon, 19 Jan 2026 10:59:53 +1100 Subject: [PATCH] Only validate fully qualified directory paths --- Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs | 2 +- Semantics.Paths/Implementations/DirectoryPath.cs | 2 +- Semantics.Paths/SemanticDirectoryPath.cs | 2 +- Semantics.Paths/SemanticRelativePath.cs | 4 ++-- ...PathAttribute.cs => IsAbsoluteDirectoryPathAttribute.cs} | 6 +++--- Semantics.Test/PathValidationAttributeTests.cs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename Semantics.Paths/Validation/Attributes/Path/{IsDirectoryPathAttribute.cs => IsAbsoluteDirectoryPathAttribute.cs} (84%) diff --git a/Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs b/Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs index 3300d3a..3ad2203 100644 --- a/Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs +++ b/Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs @@ -9,7 +9,7 @@ namespace ktsu.Semantics.Paths; /// /// Represents an absolute directory path /// -[IsPath, IsAbsolutePath, IsDirectoryPath] +[IsPath, IsAbsolutePath, IsAbsoluteDirectoryPath] public sealed record AbsoluteDirectoryPath : SemanticDirectoryPath, IAbsoluteDirectoryPath { // Cache for expensive parent directory computation diff --git a/Semantics.Paths/Implementations/DirectoryPath.cs b/Semantics.Paths/Implementations/DirectoryPath.cs index 50d5c30..6e8a55f 100644 --- a/Semantics.Paths/Implementations/DirectoryPath.cs +++ b/Semantics.Paths/Implementations/DirectoryPath.cs @@ -9,7 +9,7 @@ namespace ktsu.Semantics.Paths; /// /// Represents a directory path (path to a directory) /// -[IsPath, IsDirectoryPath] +[IsPath, IsAbsoluteDirectoryPath] public sealed record DirectoryPath : SemanticDirectoryPath, IDirectoryPath { /// diff --git a/Semantics.Paths/SemanticDirectoryPath.cs b/Semantics.Paths/SemanticDirectoryPath.cs index e9ea7dc..a13280f 100644 --- a/Semantics.Paths/SemanticDirectoryPath.cs +++ b/Semantics.Paths/SemanticDirectoryPath.cs @@ -7,7 +7,7 @@ namespace ktsu.Semantics.Paths; /// /// Base class for directory paths (paths that represent directories) /// -[IsPath, IsDirectoryPath] +[IsPath] public abstract record SemanticDirectoryPath : SemanticPath where TDerived : SemanticDirectoryPath { diff --git a/Semantics.Paths/SemanticRelativePath.cs b/Semantics.Paths/SemanticRelativePath.cs index 37468fb..07eab3a 100644 --- a/Semantics.Paths/SemanticRelativePath.cs +++ b/Semantics.Paths/SemanticRelativePath.cs @@ -80,11 +80,11 @@ public static TRelativePath Make(TFromPath fr /// /// The type of semantic path to check. /// The path instance to check. - /// if the path type has the ; otherwise, . + /// if the path type has the ; otherwise, . private static bool IsDirectoryPath(T path) where T : SemanticPath { // Check if it's a directory-specific type based on validation attributes Type type = path.GetType(); - return type.GetCustomAttributes(typeof(IsDirectoryPathAttribute), true).Length > 0; + return type.GetCustomAttributes(typeof(IsAbsoluteDirectoryPathAttribute), true).Length > 0; } } diff --git a/Semantics.Paths/Validation/Attributes/Path/IsDirectoryPathAttribute.cs b/Semantics.Paths/Validation/Attributes/Path/IsAbsoluteDirectoryPathAttribute.cs similarity index 84% rename from Semantics.Paths/Validation/Attributes/Path/IsDirectoryPathAttribute.cs rename to Semantics.Paths/Validation/Attributes/Path/IsAbsoluteDirectoryPathAttribute.cs index 80d2c80..d59797c 100644 --- a/Semantics.Paths/Validation/Attributes/Path/IsDirectoryPathAttribute.cs +++ b/Semantics.Paths/Validation/Attributes/Path/IsAbsoluteDirectoryPathAttribute.cs @@ -12,18 +12,18 @@ namespace ktsu.Semantics.Paths; /// Validates that a path represents a directory (not an existing file) /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] -public sealed class IsDirectoryPathAttribute : NativeSemanticStringValidationAttribute +public sealed class IsAbsoluteDirectoryPathAttribute : NativeSemanticStringValidationAttribute { /// /// Creates the validation adapter for directory path validation. /// /// A validation adapter for directory paths - protected override ValidationAdapter CreateValidator() => new DirectoryPathValidator(); + protected override ValidationAdapter CreateValidator() => new AbsoluteDirectoryPathValidator(); /// /// validation adapter for directory paths. /// - private sealed class DirectoryPathValidator : ValidationAdapter + private sealed class AbsoluteDirectoryPathValidator : ValidationAdapter { /// /// Validates that a path represents a directory by ensuring it's not an existing file. diff --git a/Semantics.Test/PathValidationAttributeTests.cs b/Semantics.Test/PathValidationAttributeTests.cs index 4ee6b31..78f603d 100644 --- a/Semantics.Test/PathValidationAttributeTests.cs +++ b/Semantics.Test/PathValidationAttributeTests.cs @@ -421,7 +421,7 @@ public record TestRelativePath : SemanticString { } [IsValidFileName] public record TestFileName : SemanticString { } -[IsDirectoryPath] +[IsAbsoluteDirectoryPath] public record TestDirectoryPath : SemanticString { } [IsFilePath]