Skip to content

Conversation

@ap--
Copy link
Contributor

@ap-- ap-- commented Mar 10, 2024

Closes #116393

Hello everyone,

this PR makes glob.translate match empty path parts (or consecutive path separators, i.e. "foo//bar") with "**" when recursive=True.

When I first implemented the change, I noticed that a pattern that starts with "**" would also match paths that start with "/", because they start with an 'empty part'.

So I added a negative lookahead to the beginning of the regex in case the pattern starts with "**", see: 1624308

This prevents glob.translate("**", recursive=True).match from matching "/foo", which is intuitive for me.

edit: "**" matching "/" is in line with pathlib

>>> import pathlib
>>> pathlib.Path("/").full_match("**")
True

Cheers,
Andreas

@ap--
Copy link
Contributor Author

ap-- commented Mar 10, 2024

I think that change introduced problems with pathlib. I'll work on a fix.

@ap--
Copy link
Contributor Author

ap-- commented Mar 10, 2024

Okay, it looks like "**" matching "/foo" is intentional:

self.assertTrue(P('/a/b/c.py').full_match('**'))
self.assertTrue(P('/a/b/c.py').full_match('/**'))

@barneygale barneygale self-assigned this Mar 10, 2024
@barneygale barneygale self-requested a review March 10, 2024 21:55
@barneygale barneygale removed their assignment Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

glob.translate("a/**/c", recursive=True, include_hidden=True) does not match "a//c"

2 participants