You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Directory Depth counts separator characters: "/" and "/home" both have depth 1, and "a" (0) and "./a" (1) differ although they name the same directory #466
AbsoluteDirectoryPath.Depth (Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs:80-98) and RelativeDirectoryPath.Depth (RelativeDirectoryPath.cs:84-100) count every / or \ character in the string:
The root's own separator therefore counts as one level, and . and .. segments count like real directories.
Observed (ktsu.Semantics.Paths 5.12.1; the code is unchanged on main)
Path
Depth
Expected
/
1
0
/home
1
1
C:\ (Windows)
1
0
C:\Users (Windows)
1
1
a (relative)
0
0
./a (relative)
1
0 (same directory as a)
a/.. (relative)
1
the starting directory
Consequences:
x.Parent.Depth < x.Depth does not hold when x is a child of the root.
Sorting or comparing by depth, as PathIntegrationTests.DirectoryDepth_Comparison does, puts the root level with its own children.
Two spellings of the same relative directory report different depths.
Suggested fix / acceptance criteria
Count non-empty segments after the root, skipping . and resolving .. lexically. The root then has depth 0 and /home has depth 1.
For relative paths, compute depth from the normalised form. Keep the current convention that a is 0 and a/b is 1, so existing tests that rely on it still pass.
Add tests for the root, a child of the root, a trailing separator (/home/), ./a, and a/.., on both POSIX and Windows-style roots.
Related but distinct: #446 (Parent and GetAncestors ignore . and ..).
Priority: Medium. Depth gives wrong values for the root (1 instead of 0) and for . and .. spellings, which breaks the Parent.Depth < Depth invariant and depth-based sorting. It is a wrong result, not a crash.
Area / suggested assignee:Depth in Semantics.Paths (AbsoluteDirectoryPath, RelativeDirectoryPath). Owner: @matt-edmondson
Activity
matt-edmondson commentedon Oct 18, 2026
Triage
Depthgives wrong values for the root (1 instead of 0) and for.and..spellings, which breaks theParent.Depth < Depthinvariant and depth-based sorting. It is a wrong result, not a crash.DepthinSemantics.Paths(AbsoluteDirectoryPath,RelativeDirectoryPath). Owner: @matt-edmondsonParent/GetAncestors. That PR does not changeDepth, but whatever lexical normalisation it adds could be reused here. Open PR Apply the Windows path character and length rules only on Windows [patch] #463 (Windows-only path rules) touches the same package../aanda/..tests.Generated by Claude Code