ConfigParser chokes on conflict markers in stdin and throws AttributeError
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em configparser.py, em ConfigParser._read, especialmente no tratamento de continuação em torno da linha relatada cursect[optname].append(value). Reproduza o caso com allow_no_value=True e uma entrada com marcadores de conflito por meio de stdin, depois adicione cobertura de regressão mostrando que o analisador não gera mais AttributeError e verifique se o comportamento existente continua adequado.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 48/100