ConfigParser chokes on conflict markers in stdin and throws AttributeError
未关闭
还没有人认领这个 Issue。
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
This is probably a duplicate of bug 107625, but I do not have a recent enough version of Python to check the behaviour.
Whether it is worth specially detecting conflict markers is something the code owners can decide.
To reproduce:
/tmp/py:
#!/usr/bin/python3
import configparser
import sys
sl = configparser.ConfigParser(allow_no_value=True)
sl.read_file(sys.stdin)
/tmp/z:
[list]
<<<<<<<< HEAD (f12435 blah)
foo
|||||||| BASE
bar
========
baz
>>>>>>>> CHANGE (faa768 blah)
$ </tmp/z /tmp/py
Traceback (most recent call last):
File "/tmp/py", line 7, in <module>
sl.read_file(sys.stdin)
File "/usr/lib/python3.11/configparser.py", line 734, in read_file
self._read(f, source)
File "/usr/lib/python3.11/configparser.py", line 1077, in _read
cursect[optname].append(value)
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'
Notes:
sys.stdinseems to be needed to trigger this - deserves further investigation because it may point to a bad assumption or similar in the parserallow_no_valueis needed to trigger this
Finger of blame:
if (cursect is not None and optname and
cur_indent_level > indent_level):
cursect[optname].append(value)
This does not check that cursect[optname] is present.
CPython versions tested on:
3.10, 3.11, 3.12
Operating systems tested on:
Linux
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 configparser.py 中的 ConfigParser._read 开始,重点检查报告的 cursect[optname].append(value) 行附近的续行处理。使用 allow_no_value=True 和通过 stdin 输入的冲突标记输入重现该情况,然后添加回归覆盖,显示解析器不再引发 AttributeError,并验证现有行为仍然合适。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100