Skip to content

AbsoluteDirectoryPath.Parent and GetAncestors() ignore "." and ".." segments: parent of "/home/user/.." is "/home/user" #446

Closed

Description

@matt-edmondson

What's wrong

AbsoluteDirectoryPath.Parent (Semantics.Paths/Implementations/AbsoluteDirectoryPath.cs, about lines 45-63) computes Path.GetDirectoryName(WeakString) on the raw string. GetAncestors() (about line 230) is built on Parent.

SemanticPath.MakeCanonical only normalises separators and trailing slashes, and IsAbsolutePathAttribute accepts . and .. segments. So a dot segment is treated as an ordinary directory name. IsChildOf in the same file already resolves with Path.GetFullPath, so the type is internally inconsistent.

This is the absolute-path twin of #387, which PR #423 fixed only for RelativeDirectoryPath: it calls Normalize() before taking the parent.

Reproduction (net10.0)

var p = AbsoluteDirectoryPath.Create<AbsoluteDirectoryPath>("/home/user/..");
p.Parent;          // "/home/user"   expected "/"  (p names /home)
p.GetAncestors();  // /home/user, /home, /   (first "ancestor" is a child of p itself)

AbsoluteDirectoryPath.Create<AbsoluteDirectoryPath>("/home/user/.").Parent; // "/home/user", expected "/home"

Code that walks upward with GetAncestors() visits the wrong directories. Typical cases are looking for a config file or repo root, or a containment check.

Suggested fix

  • In Parent, resolve first: Path.GetDirectoryName(Path.GetFullPath(WeakString)). On netstandard2.0, use the existing PathPolyfill.
  • Keep the rule that a root returns itself.

Acceptance criteria

  • Parent and GetAncestors() give the resolved parent chain for inputs containing . and .., on both Windows-style and Unix-style paths.
  • Tests are added alongside Semantics.Test/Paths/AbsoluteDirectoryPathParentTests.cs.

Activity

  1. added
    bug
    on Oct 18, 2026
  2. matt-edmondson commented on Oct 18, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions