Skip to content

LocalPath.IsPrefixOf: account for leading .. references - #234

Open
rghvgrv wants to merge 1 commit into
ForNeVeR:mainfrom
rghvgrv:fix/226-isprefixof-parent-references
Open

rghvgrv wants to merge 1 commit into
ForNeVeR:mainfrom
rghvgrv:fix/226-isprefixof-parent-references

Conversation

@rghvgrv

@rghvgrv rghvgrv commented Sep 25, 2026

Copy link
Copy Markdown

Closes #226.

IsPrefixOf compared relative paths as strings, which breaks once a path begins with ..:

new LocalPath("..").IsPrefixOf(new LocalPath("foo"));   // was false, now true
new LocalPath("..").IsPrefixOf(new LocalPath("../.."));  // was true, now false

A relative path is now split into the number of its leading .. references and the remaining segments:

  • same number of .. references: the remaining segments are compared as before (whole-segment, platform-default case sensitivity);
  • the prefix starts higher up: it's a prefix only if it is a bare train of .. references (.., ../.., …); otherwise it names a directory that is only known after resolving the current directory, so the result is false;
  • the prefix starts lower down: never a prefix.

This also covers the empty-path special case from #223, so that branch is folded into the general rule. Absolute paths are compared exactly as before.

Not covered here: /.. on rooted paths (mentioned in the issue). It needs a decision on whether normalization should drop .. directly after the root, so I've left it for a separate change.

Tests: added cases to LocalPathTests.IsPrefixOfAndStartsWith; the full suite passes locally.

Relative paths are compared by the number of their leading .. references
and the remaining segments, instead of as plain strings.

This branch has not been deployed

No deployments
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.

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

2 participants