ConfigParser chokes on conflict markers in stdin and throws AttributeError
オープン
まだ誰も着手していません。
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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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