`utf-7-imap` incremental decoder and stream reader fail on split input
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
utf-7-imap registers an incremental decoder and a stream reader that call the one-shot decoder with no state, so a shift sequence split across chunks raises instead of being buffered. io.TextIOWrapper.read(n), codecs.iterdecode and codecs.StreamReader.read all fail on bytes the codec's own encoder produced.
import io
text = '台' * 5000
data = text.encode('utf-7-imap')
f = io.TextIOWrapper(io.BytesIO(data), encoding='utf-7-imap')
print(f.read(100) == text[:100])
UnicodeDecodeError: 'utf-7-imap' codec can't decode bytes in position 0-8191: unterminated shift sequence
Expected: True. Doc/library/codecs.rst says the joined output of calls to the incremental decode method is the same as decoding the joined input with the stateless decoder.
The incremental encoder breaks the same sentence more mildly: encoding '~peter/mail/台北/日本語' one character at a time joins to b'~peter/mail/&U,A-&Uxc-/&ZeU-&Zyw-&ip4-' where one shot gives b'~peter/mail/&U,BTFw-/&ZeVnLIqe-', though both decode back to the same text.
The codec is new in 3.16, so no released version is affected.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-156967
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 utf-7-imap 的增量解码器和流读取器路径开始,这些路径由 io.TextIOWrapper.read、codecs.iterdecode 和 codecs.StreamReader.read 使用。阅读 Doc/library/codecs.rst 中关于增量 codec 的指导,然后验证拆分输入能够正常工作,并且合并后的增量结果与无状态解码器的行为一致。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 20/100