Skip to content

Match path containment case to the platform and accept paths directly under a root [patch] - #296

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/path-containment-case-and-root
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/path-containment-case-and-root

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #291
Fixes #282

Both issues are in the same prefix check, and both triage notes asked for them to be fixed together, so this is one PR.

What was wrong

Change

  • New internal PathContainment helper, used by AbsoluteDirectoryPath.IsChildOf (and so IsParentOf) and AbsoluteFilePath.IsChildOf. This replaces three copies of the check, including the separate netstandard2.0 branch.
    • Comparison: OrdinalIgnoreCase on Windows, Ordinal everywhere else. The triage asked for an explicit decision on macOS: I chose Ordinal, the same comparison that path equality and hashing already use. APFS is case-insensitive by default but can be formatted case-sensitive, and ordinal is the choice that can't report a sibling as a child. The reasoning is written down in the helper's remarks.
    • Same path: the child must be strictly longer than the parent, so a path is never its own child. This also holds for a spelling that differs only in case.
    • Root: a parent that ends in a separator contains every longer path that starts with it. Otherwise the match must still end at a separator, so /home2 is not inside /home.
  • Updated the XML docs, which described the old span-based implementation.

Tests

New PathContainmentTests, built from TestPaths so they run on every platform:

  • A directory and a file under a differently cased sibling are children only on Windows. IsParentOf is checked too.
  • A differently cased spelling of the same directory is never a child.
  • A directory and a file directly under the root, and deeper paths, are children of the root. home.Parent == root is checked alongside.
  • The root is not a child of itself.
  • home2, home2/user, and home2.txt are not children of home.

Before the fix, 5 of the 8 tests failed on Linux: both case tests, and all three root tests. With the fix, the full Semantics.Test suite passes (1344 passed, 8 skipped), and Semantics.Paths builds for all five targets with no warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PHrrj7bWzA48Gf3akqi476


Generated by Claude Code

… under a root [patch]

IsChildOf/IsParentOf compared prefixes case-insensitively on every platform, so
on Linux /home/user/DOCS/report was reported as inside /home/user/docs. They also
required a separator after the parent, which a root already ends in, so /home was
not a child of /. Both types now share one rule: ordinal-ignore-case on Windows,
ordinal elsewhere (macOS included), and a parent ending in a separator contains
every longer path that starts with it.

Fixes #291
Fixes #282

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 76e3fd0 into main Sep 28, 2026
13 checks passed
@matt-edmondson
matt-edmondson deleted the fix/path-containment-case-and-root branch September 28, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant