Skip to content

Resolve dot segments in AbsoluteDirectoryPath.Parent and GetAncestors [patch] - #453

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/446-absolute-parent-dot-segments
Oct 18, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/446-absolute-parent-dot-segments

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #446

Summary

Before: AbsoluteDirectoryPath.Parent called Path.GetDirectoryName on the raw text, so . and .. were treated as ordinary directory names. The parent of /home/user/.. came back as /home/user, a child of the path itself. GetAncestors() is built on Parent, so it walked the wrong chain too.

After: Parent resolves the path with Path.GetFullPath before dropping the last segment, the same resolution IsChildOf in this type already uses. A root is still its own parent. Path.GetFullPath exists on every target, and PathPolyfill already calls it on netstandard2.0. This is the absolute-path counterpart of the RelativeDirectoryPath fix in #423.

Tests

  • AbsoluteDirectoryPathParentTests.Parent_ResolvesDotSegments checks <root>Users/user/.. → root, …/user/. → <root>Users, …/Documents/../. → <root>Users, and …/user/../user/Documents → <root>Users/user. The tests build paths with TestPaths, so they run with Windows or Unix separators to match the host.
  • AbsoluteDirectoryPathParentTests.GetAncestors_ResolvesDotSegments checks that the ancestors of …/Documents/.. are [<root>Users, <root>].
  • With the AbsoluteDirectoryPath.cs change reverted, both new tests fail. With it in place, the full Semantics.Test suite passes on net10.0 (1701 total: 1693 passed, 8 skipped), and Semantics.Paths builds for netstandard2.0 with no warnings.

Generated by Claude Code

AbsoluteDirectoryPath.Parent called Path.GetDirectoryName on the raw
text, so "." and ".." were treated as ordinary directory names: the
parent of /home/user/.. was /home/user, a child of the path itself, and
GetAncestors, built on Parent, walked the wrong chain. IsChildOf in the
same type already resolves with Path.GetFullPath.

Parent now resolves the path the same way before dropping the last
segment. A root is still its own parent.

Fixes #446

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TUnnjk1kZxBU7o2kbNsSaP
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants