link-patterns extra replaces matches inside inline HTML tags and destroys email auto-links
Maintainer antworten meist innerhalb von 3 Tagen
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 30/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 2.8k
- Forks
- 477
- Ø Merge
- 4 T. 10 Std.
- Gemergte PRs (30 T.)
- 12
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus trentm/python-markdown2
-
Add py.typed markerEvtl. vergeben @mac-agent hat das vor 219 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
trentm/python-markdown2#696 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Code spans that wrap onto the next line are no longer recognised (regression from the #702 fix)Evtl. vergeben @awais-ur-rehman hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 55/100
trentm/python-markdown2#756 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Quadratic-time inline-link parsing: many unclosed [...]( cause a CPU DoSEvtl. vergeben @ParamTanna hat das vor 6 Tagen übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
trentm/python-markdown2#750 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 58/100
trentm/python-markdown2#688 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 58/100
trentm/python-markdown2#679 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in trentm/python-markdown2
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
521xueweihan/HelloGitHub#4237 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
jejjohnson/gaussx#721 ·
Maintainer antworten meist innerhalb von 1 Tag
-
mock-core-configs/etc/mock/rocky-10-riscv64.cfg contains the wrong architecture in config_opts['root']Evtl. vergeben @jasonmontleon hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 94/100
rpm-software-management/mock#1834 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 75/100
elastic/elastic-otel-python#683 ·
Maintainer antworten meist innerhalb von 1 Tag
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retriesOffenfollow-up
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag