glob.translate incorrectly matches path separator in character ranges
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione di glob.translate nell’issue, confrontando i pattern generati per ? e gli intervalli di caratteri quando seps=['/']. Il lavoro è completato quando gli intervalli di caratteri non corrispondono più ai separatori di percorso e il comportamento documentato è coperto da un test di regressione; nota che la PR collegata gh-130989 indica che il lavoro è già in corso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100