Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathlib.PurePath.match() can incorrectly match empty path #106330

Closed
barneygale opened this issue Jul 2, 2023 · 2 comments
Closed

pathlib.PurePath.match() can incorrectly match empty path #106330

barneygale opened this issue Jul 2, 2023 · 2 comments
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes topic-pathlib type-bug An unexpected behavior, bug, or error

Comments

@barneygale
Copy link
Contributor

barneygale commented Jul 2, 2023

>>> from pathlib import PurePath
>>> PurePath().match('*')
True

This should be false, because a * segment always consumes exactly one path component, but empty paths have 0 components.

Linked PRs

@barneygale barneygale added type-bug An unexpected behavior, bug, or error 3.12 bugs and security fixes topic-pathlib 3.13 new features, bugs and security fixes labels Jul 2, 2023
@AlexWaygood AlexWaygood changed the title pathlib.PurePath.match() can incorrectly match empty patch pathlib.PurePath.match() can incorrectly match empty path Jul 2, 2023
@barneygale
Copy link
Contributor Author

Caused by #101398. In Python 3.13 this can also affect glob() results.

barneygale added a commit to barneygale/cpython that referenced this issue Jul 2, 2023
…h()`

We match paths using the `_lines` attribute, which is derived from the
path's string representation. The bug arises because an empty path's string
representation is `'.'` (not `''`), which is matched by the `'*'` wildcard.
barneygale added a commit to barneygale/cpython that referenced this issue Jul 2, 2023
barneygale added a commit that referenced this issue Jul 3, 2023
…H-106331)

We match paths using the `_lines` attribute, which is derived from the
path's string representation. The bug arises because an empty path's string
representation is `'.'` (not `''`), which is matched by the `'*'` wildcard.
barneygale added a commit to barneygale/cpython that referenced this issue Jul 3, 2023
…th.match()` (pythonGH-106331)

We match paths using the `_lines` attribute, which is derived from the
path's string representation. The bug arises because an empty path's string
representation is `'.'` (not `''`), which is matched by the `'*'` wildcard.
(cherry picked from commit b4efdf8)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
barneygale added a commit that referenced this issue Jul 4, 2023
…ch()` (GH-106331) (GH-106372)

We match paths using the `_lines` attribute, which is derived from the
path's string representation. The bug arises because an empty path's string
representation is `'.'` (not `''`), which is matched by the `'*'` wildcard.
(cherry picked from commit b4efdf8)
@barneygale
Copy link
Contributor Author

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes topic-pathlib type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant