glob.translate incorrectly matches path separator in character ranges
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Description
The glob.translate function in Python 3.13 doesn't properly handle path separators when they're included in character ranges. According to the documentation, "wildcards do not match path separators," but this isn't enforced for character ranges that include the path separator.
Expected behavior
Character ranges in glob patterns should not match path separators, consistent with the behavior of single character wildcards (?) and the documented behavior of the module.
Actual behavior
Character ranges that include the path separator (e.g., [%-0] which includes the / character) will match the path separator, contradicting the documented behavior.
Code to reproduce
import glob
import re
# Proper behavior with ? wildcard
r1 = re.compile(glob.translate('a?c', seps=['/']))
print(r1) # (?s:a[^/]c)\Z
print(r1.match('abc')) # match object
print(r1.match('a/c')) # None, correctly doesn't match path separator
# Incorrect behavior with character range
r2 = re.compile(glob.translate('a[%-0]c', seps=['/']))
print(r2) # (?s:a[%-0]c)\Z
print(r2.match('a0c')) # match object
print(r2.match('a/c')) # match object, incorrectly matches path separator
### CPython versions tested on:
3.13
### Operating systems tested on:
_No response_
Linked PRs
- gh-130989
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the glob.translate reproduction in the issue, comparing the generated patterns for ? and character ranges when seps=['/']. Done means character ranges no longer match path separators and the documented behavior is covered by a regression test; note that linked PR gh-130989 indicates work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100