`shlex` silently discards a sourced stream when the source filename ends at EOF
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy trình tái hiện Python tối thiểu và kiểm tra trong mã nguồn của shlex.shlex phần đưa nguồn vào quanh sourcehook() cũng như cách xử lý khi kết thúc đầu vào. Được xem là hoàn tất khi stream được đưa vào tạo ra 'from-child' trước khi bị đóng, đồng thời quá trình phân tích cú pháp vẫn tiếp tục chính xác trong stream cha.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- cli
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100