Skip to content

Path canonicalization strips only one trailing separator: "/home/user/a//" stays "/home/user/a/" and IsChildOf("/home/user/a") returns true #308

Closed

Description

@matt-edmondson

What's wrong

SemanticPath.MakeCanonical removes at most one trailing directory separator. A path written with a doubled trailing separator keeps one, so it is not equal to the same directory written without it. The containment check then treats it as a child of itself.

Where

Failure scenario

These were reproduced against the built library on Linux, .NET 10:

var a  = AbsoluteDirectoryPath.Create("/home/user/a//"); // canonical: "/home/user/a/"
var b  = AbsoluteDirectoryPath.Create("/home/user/a");   // canonical: "/home/user/a"
a == b                 // false
a.IsChildOf(b)         // true: a directory reported as inside itself

Doubled separators are common in paths built by string concatenation (dir + "/" + sub where dir already ends in /). Code that uses IsChildOf to guard against acting on the root of a tree, or to detect recursion, gets the wrong answer.

Suggested fix

  • In MakeCanonical, trim all trailing separators, stopping at the root (/ or C:\). For example, TrimEnd(separator) and then restore the root if the result became empty or C:.
  • Optionally, make PathContainment ignore a trailing separator on the child before comparing lengths, so it is robust on its own.
  • Add tests: "/a//" equals "/a", IsChildOf is false for that pair, and "//" still canonicalizes to the root.

Activity

  1. matt-edmondson commented on Sep 28, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

  2. added a commit that references this issue on Oct 14, 2026
    31f4fb2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions