Skip to content

AbsoluteDirectoryPath.IsRoot is false for /home/.. while Parent returns the path itself, so while (!dir.IsRoot) dir = dir.Parent never ends #479

Closed

Description

@matt-edmondson

What's wrong

Since #446, Parent resolves dot segments with Path.GetFullPath, and when the resolved path has no parent it returns this (AbsoluteDirectoryPath.cs#L50-L66).``

IsRoot still compares the unresolved string with its root (L118):

public bool IsRoot => _cachedIsRoot ??= Path.GetPathRoot(WeakString) == WeakString;

The XML docs on Parent (L39-L43) tell callers to detect the end of an upward walk by checking IsRoot, or by comparing the parent with this path. For a path that resolves to a root, those two signals now disagree.

Reproduction (net10.0, Linux, observed)

var d = AbsoluteDirectoryPath.Create<AbsoluteDirectoryPath>("/home/..");
d.Parent == d;           // true  (resolved "/" has no parent, so Parent returns this)
d.IsRoot;                // false
d.GetAncestors().Count() // 0

// The documented idiom spins forever:
while (!d.IsRoot) { d = d.Parent; }

/home/user/../.. behaves the same way, and so does C:\Windows\.. on Windows.

Related: Name (L75) returns the literal last segment, so "/home/user/..".Name is "..". That matches its "last component" doc, but it should either be called out in the docs or resolved the same way.

Suggested fix

  • Compute IsRoot on the resolved path, either as string full = Path.GetFullPath(WeakString); Path.GetPathRoot(full) == full or as the equivalent Parent == this.
  • Use PathPolyfill where netstandard2.0 needs it.

Acceptance criteria

  • IsRoot is true exactly when Parent returns the path itself, including for /home/.., /home/user/../.. and C:\x\...
  • A test walks while (!d.IsRoot) d = d.Parent; from a dotted path and stops at the root.

Activity

  1. added
    bug
    on Oct 20, 2026
  2. matt-edmondson commented on Oct 20, 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