`shlex` silently discards a sourced stream when the source filename ends at EOF
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore minimo in Python e ispeziona nel codice sorgente di shlex.shlex l'inclusione delle sorgenti attorno a sourcehook() e la gestione della fine dell'input. Il lavoro è completato quando lo stream incluso produce 'from-child' prima di essere chiuso, mentre il parsing riprende correttamente nello stream padre.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- cli
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100