GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pathlib.PureWindowsPath.match() mishandles path anchors · Issue #101360 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
pathlib.PureWindowsPath.match() mishandles path anchors#101360
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixesOS-windowstopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@barneygale
barneygale
opened on Jan 26, 2023
Issue body actions

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

  • gh-101360: Fix anchor matching in pathlib.PureWindowsPath.match() #101363

Activity

  1. barneygale
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.11only security fixesonly security fixes
    3.10 (EOL)end of lifeend of life
    3.12only security fixesonly security fixes
    topic-pathlib
    on Jan 26, 2023
  2. AlexWaygood
    added
    OS-windows
    on Jan 26, 2023
  3. barneygale commented on Jan 27, 2023

    @barneygale
    barneygale
    on Jan 27, 2023
    ContributorAuthor
    More actions

    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).

  4. barneygale
    added 3 commits that reference this issue on Jan 27, 2023

    pythongh-101360: Fix anchor matching in pathlib.PureWindowsPath.match()

    85b8e4c

    pythongh-101360: Fix anchor matching in pathlib.PureWindowsPath.match()

    13e9330

    Merge branch 'main' into pythongh-101360-fix-match-partial-anchor

    ef53ea0
  5. zooba
    added a commit that references this issue on Feb 17, 2023

    gh-101360: Fix anchor matching in pathlib.PureWindowsPath.match() (GH…

    d401b20
  6. barneygale commented on Feb 17, 2023

    @barneygale
    barneygale
    on Feb 17, 2023
    ContributorAuthor
    More actions

    Fixed in #101363 / d401b20

  7. barneygale
    closed this as completedon Feb 17, 2023
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)end of lifeend of life3.11only security fixesonly security fixes3.12only security fixesonly security fixesOS-windowstopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.