Skip to content

IsPrefixOf compares segment strings, not directory depth, for paths with leading ".." #226

Closed

Description

@ForNeVeR

IsPrefixOf decides containment by comparing normalized path strings segment by segment. That is correct as long as neither path begins with a .. reference — but .. moves up, so a string prefix stops implying containment:

new LocalPath("..").IsPrefixOf(new LocalPath("foo"));    // false, though foo is CWD/foo, which is under ..
new LocalPath("..").IsPrefixOf(new LocalPath("../.."));  // true, though ../.. is above .., not under it

Answering these correctly means modelling how far above the current directory a path starts — the number of leading .. references — and comparing that together with the remaining segments, rather than comparing strings.

This affects AbsolutePath too: /.. survives normalization, so new AbsolutePath("/..") is a constructible value.

Both behaviors predate #223. A closely related case was fixed there: the empty path (the current directory) was reported as a prefix of ../evil.

Activity

  1. rghvgrv commented on Sep 25, 2026

    @rghvgrv
    Contributor

    Provided the fix for this in PR #234

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions