Skip to content

LocalPath: prefix matching needs a four-way path kind, not IsPathRooted #224

Description

@ForNeVeR

LocalPath.IsPrefixOf uses IsAbsolute (i.e. Path.IsPathRooted) to refuse comparisons between paths of differing absoluteness. That is only an approximation, because on Windows there are really four kinds of path, and no path of one kind should ever be considered a prefix of a path of another:

  1. true absolute — C:\Windows
  2. rooted diskless — \Windows
  3. current on disk — C: (and C:Windows, relative to the current directory of drive C:)
  4. true relative — Windows, ..\Windows

AbsolutePath exists to cover kind 1 only, while LocalPath is applicable to all four. IsPathRooted answers true for kinds 1, 2 and 3 alike, so the current check only separates {1, 2, 3} from {4}.

Kind 3 is genuinely representable: PathStrings.Normalize returns "C:" for input "C:", so new LocalPath("C:") is a real value. It is currently reported as a prefix of C:\Windows, which is wrong.

LocalPath.IsAbsolute is already documented as subject to narrowing to kind 1. When that happens, IsPrefixOf must not simply follow it — it needs the full four-way distinction, so the path kind should be extracted into a separate field or property and matched on there. Both carry a TODO pointing here, and both must be resolved in one change.

Related to #23 (the WIP RelativePath type), but distinct: this is about LocalPath carrying a path kind internally.

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions