`shlex` silently discards a sourced stream when the source filename ends at EOF
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug description:
Summary
When shlex.shlex source inclusion is enabled and the filename following the source directive is the final token in the parent input, with no trailing whitespace or newline, the stream returned by sourcehook() is opened or created normally but all of its tokens are silently discarded. The included stream is then closed.
It contradicts the documented source-inclusion semantics, under which input should be read from the included stream until EOF before parsing resumes in the parent stream.
Minimal reproducer
import io
import shlex
lexer = shlex.shlex("include child", posix=True)
lexer.source = "include"
included = io.StringIO("from-child")
lexer.sourcehook = lambda filename: (filename, included)
print(list(lexer))
print(included.closed)
Actual behavior
[]
True
The from-child token is never returned, and the included stream is closed. No exception is raised, so callers cannot detect from the token stream that included input was skipped.
Expected behavior
['from-child']
True
The included stream should be parsed completely, closed when it reaches EOF, and only then should parsing resume in the parent stream.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-156892
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先執行最小的 Python 重現程式,並檢查 shlex.shlex 原始碼中 sourcehook() 附近的來源包含邏輯以及輸入結尾處理。完成的標準是:被包含的串流在關閉之前產生 'from-child',同時解析仍能在父串流中正確繼續。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- cli
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100