`shlex` silently discards a sourced stream when the source filename ends at EOF
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
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 executando o reprodutor mínimo em Python e inspecione, no código-fonte de shlex.shlex, a inclusão de fontes em torno de sourcehook() e o tratamento do fim da entrada. Está concluído quando o stream incluído produz 'from-child' antes de ser fechado, enquanto o parsing continua corretamente no stream pai.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- cli
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 25/100