Reused `Markdown` instance keeps link URLs and code spans from earlier documents
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 2.8k
- フォーク
- 477
- 平均マージ
- 4日 6時間
- マージ済み PR(30日)
- 12
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
trentm/python-markdown2 のほかの issue
-
Add py.typed marker対応中かも @mac-agent が 220 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
trentm/python-markdown2#696 ·
メンテナーはふだん 3 日以内に返信
-
Code spans that wrap onto the next line are no longer recognised (regression from the #702 fix)対応中かも @awais-ur-rehman が 5 日前に担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 55/100
trentm/python-markdown2#756 ·
メンテナーはふだん 3 日以内に返信
-
link-patterns extra replaces matches inside inline HTML tags and destroys email auto-links対応中かも @rahul05ranjan が 6 日前に担当しました。 オープンBug
難易度 3/5 1〜2日 初心者へのやさしさ 30/100
trentm/python-markdown2#752 ·
メンテナーはふだん 3 日以内に返信
-
Quadratic-time inline-link parsing: many unclosed [...]( cause a CPU DoS対応中かも @ParamTanna が 7 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
trentm/python-markdown2#750 ·
メンテナーはふだん 3 日以内に返信
-
Bug
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
trentm/python-markdown2#688 · コメント 4 件 ·
メンテナーはふだん 3 日以内に返信
trentm/python-markdown2 の issue をすべて見る
似ている issue
-
bug module:nodes tests
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
rocketride-org/rocketride-server#3020 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
bretterer/home-assistant-rivian#335 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
mampfes/hacs_waste_collection_schedule#8114 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
TIGER-AI-Lab/ClawBench#475 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
UKGovernmentBEIS/inspect_ai#6322 ·
メンテナーはふだん 1 日以内に返信