Reused `Markdown` instance keeps link URLs and code spans from earlier documents
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 53/100
Hướng nghiên cứu
Read reset() and the initialization path in the Markdown class, especially how _escape_table and _code_table are used by _setup_extras(). The issue provides a reproducer showing the URL escaping difference and reports that resetting both tables should preserve single document output. Verify reused instances match fresh instances across successive convert() calls and check the existing tests for regression coverage.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
reset() doesn't clear _escape_table or _code_table, so a reused Markdown() (as in the README's markdowner example) keeps every URL and code span it has seen. markdown2.markdown() is unaffected.
It slows down. One instance, 40 documents of 200 links and 200 code spans each:
| Document | Reused | New instance |
|---|---|---|
| 1st | 9.4 ms | 8.5 ms |
| 10th | 74.6 ms | 8.6 ms |
| 40th | 349.9 ms | 8.6 ms |
It also changes output: a backslash before a URL seen in an earlier document disappears.
To Reproduce
import markdown2
md = markdown2.Markdown()
md.convert("[a link](https://example.com/page)")
print(md.convert(r"Type \https://example.com/page to see it."))
# <p>Type https://example.com/page to see it.</p>
print(markdown2.Markdown().convert(r"Type \https://example.com/page to see it."))
# <p>Type \https://example.com/page to see it.</p>
Expected behavior
Each convert() matches a new instance in output and time.
Debug info
Version: master (cecee4f). Released versions too: code spans since 2.4.3, URLs since 2.4.7.
Extras: none.
Additional context
Fix: set both tables up in a helper called from __init__ and from reset() (before _setup_extras(), which reads _escape_table for middle-word-em). Output for a single document is unchanged across all test cases.
Threading: instances aren't thread-safe now (reset() already replaces urls, titles, and html_blocks). Shared across threads, inline links and code spans survive on master only because their tables never reset. With the fix, 4 threads sharing one instance got 9 to 10 of 120 documents wrong (master: 0). With reference links, master already gets about half wrong.
Patch: https://github.com/ptweezy/python-markdown2/commit/16426734f4d656165f08b9e7ee4c09856655da3a
- Ngôn ngữ chính
- Python
- Star
- 2.8k
- Fork
- 477
- Merge trung bình
- 4 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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.
Issue khác của trentm/python-markdown2
-
Add py.typed markerCó thể đã có người làm @mac-agent đã nhận 220 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
trentm/python-markdown2#696 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Code spans that wrap onto the next line are no longer recognised (regression from the #702 fix)Có thể đã có người làm @awais-ur-rehman đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 55/100
trentm/python-markdown2#756 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
link-patterns extra replaces matches inside inline HTML tags and destroys email auto-linksCó thể đã có người làm @rahul05ranjan đã nhận 7 ngày trước. Đang mởBug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
trentm/python-markdown2#752 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Quadratic-time inline-link parsing: many unclosed [...]( cause a CPU DoSCó thể đã có người làm @ParamTanna đã nhận 7 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
trentm/python-markdown2#750 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
trentm/python-markdown2#688 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của trentm/python-markdown2
Issue tương tự
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Official-Space-AI/OpenPhysGraspGen#114 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
changelog investigate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ramnes/notion-sdk-py#441 ·
-
qa_bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA-NeMo/Gym#5644 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG: catalog database credentials printed to logs at startupCó thể đã có người làm @cjboyle đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày