glob.translate incorrectly matches path separator in character ranges
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 issue 中的 glob.translate 重現開始,比較 seps=['/'] 時為 ? 和字元範圍產生的模式。當字元範圍不再符合路徑分隔符號,且文件所述行為已由回歸測試涵蓋時,即視為完成;請注意,連結的 PR gh-130989 表示相關工作已經在進行中。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100