Skip to content

pathlib.PureWindowsPath.match() mishandles path anchors #101360

Closed

Description

@barneygale

pathlib.PurePath.match() doesn't use fnmatch() to match path anchors, contrary to the documentation. Instead, it considers the drive and root of the pattern separately; if either (or both) is specified in the pattern, it must exactly match the corresponding drive/root in the path.

This results in the following:

>>> from pathlib import PureWindowsPath as P
>>> P('c:/b.py').match('*:/*.py')
False
>>> P('c:/b.py').match('c:*.py')
True
>>> P('c:/b.py').match('/*.py')
True
>>> P('//some/share/a.py').match('//*/*/*.py')
False
>>> P('//some/share/a.py').match('/*.py')
True

All of these results are wrong IMO.

Linked PRs

Activity

  1. added
    type-bug
    3.11
    3.10 (EOL)
    3.12
    on Jan 26, 2023
  2. barneygale commented on Jan 27, 2023

    @barneygale
    ContributorAuthor

    I think I know why this behaviour is here: pathlib originally wouldn't parse patterns like *:/ because it required drive letters to be alphabetic. match() worked around this by treating empty drives like *.

    The alphabetic drive requirement was removed in 2ba0fd5 (3.12).

  3. added 3 commits that reference this issue on Jan 27, 2023
  4. added a commit that references this issue on Feb 17, 2023
  5. barneygale commented on Feb 17, 2023

    @barneygale
    ContributorAuthor

    Fixed in #101363 / d401b20

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

    3.10 (EOL)3.113.12OS-windowstopic-pathlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions