link-patterns extra replaces matches inside inline HTML tags and destroys email auto-links
メンテナーはふだん 3 日以内に返信
評価
調査の方向性
Start by reading LinkPatterns.run and is_inside_link in lib/markdown2.py, then inspect the inline HTML tokenization and auto-link tests. Reproduce the three examples with the link-patterns extra and compare them with output without it. Done means matches in prose are linkified while tag attributes and email auto-link tokens remain intact; pull request #753 is already open.
索引モデルが issue の本文から書いたものです。
説明
Summary
With the link-patterns extra enabled, a pattern that matches inside an inline HTML tag (its attributes) or inside a <...> auto-link token gets replaced there, corrupting the HTML and destroying email auto-links. The same input renders correctly without the extra.
Repro
import re
import markdown2
lp = [(re.compile(r"\b(word)\b"), r"/w/\1")]
print(markdown2.markdown('See <span title="word">x</span>', extras=["link-patterns"], link_patterns=lp))
print(markdown2.markdown('<[email protected]>', extras=["link-patterns"], link_patterns=lp))
print(markdown2.markdown('<img src="/x.png" alt="word">', extras=["link-patterns"], link_patterns=lp))
Output with the extra:
<p>See <span title="<a href="/w/word">word</a>">x</span></p>
<p><<a href="/w/word">word</a>@example.com></p>
<p><img src="/x.png" alt="<a href="/w/word">word</a>"></p>
Expected (matches what plain markdown2 does for the markup, while prose matches are linkified):
<p>See <span title="word">x</span></p>
<p><a href="mailto:[email protected]">[email protected]</a></p>
<p><img src="/x.png" alt="word"></p>
Three distinct symptoms:
<span title="word">x</span>— an anchor gets inserted inside thetitleattribute value, producing invalid HTML (and, depending on the pattern, allowing attribute content to be rewritten inside a raw tag).<[email protected]>— the mailto auto-link is destroyed entirely: the match splits the token so the auto-linker no longer recognizes it, and the angle brackets end up escaped.<img src="/x.png" alt="word">— thealtattribute is corrupted the same way.
Root cause
LinkPatterns.run (lib/markdown2.py) guards matches with is_inside_link, which checks only _auto_link_re (<http://...> style auto-links) and _basic_link_re (markdown [...](...) syntax) — #385/#446 covered those. It does not check the other tokens that markdown2's own tokenizer _sorta_html_tokenize_re classifies as inline HTML markup: tags, comments, processing instructions and <[email protected]> style auto-link tokens. _do_auto_links runs after _do_links, so at the time the extra runs the email auto-link is still the raw <[email protected]> text and a match inside it destroys it.
Environment
python-markdown2 2.5.6 (current master, 6e89cff), Python 3.13, Linux.
- 主要言語
- 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 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 53/100
trentm/python-markdown2#763 ·
メンテナーはふだん 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 日以内に返信
-
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 日以内に返信