link-patterns extra replaces matches inside inline HTML tags and destroys email auto-links
Les mainteneurs répondent en général sous 3 jours
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 30/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 2.8k
- Forks
- 477
- Merge moyen
- 4 j 10 h
- PR mergées (30 j)
- 12
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de trentm/python-markdown2
-
Add py.typed markerPeut-être pris @mac-agent l’a pris il y a 219 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
trentm/python-markdown2#696 ·
Les mainteneurs répondent en général sous 3 jours
-
Code spans that wrap onto the next line are no longer recognised (regression from the #702 fix)Peut-être pris @awais-ur-rehman l’a pris il y a 4 jours. Ouverte
Difficulté 4/5 1-2 jours Accessibilité débutants 55/100
trentm/python-markdown2#756 ·
Les mainteneurs répondent en général sous 3 jours
-
Quadratic-time inline-link parsing: many unclosed [...]( cause a CPU DoSPeut-être pris @ParamTanna l’a pris il y a 6 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
trentm/python-markdown2#750 ·
Les mainteneurs répondent en général sous 3 jours
-
Bug
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
trentm/python-markdown2#688 · 4 commentaires ·
Les mainteneurs répondent en général sous 3 jours
-
Bug
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
trentm/python-markdown2#679 · 2 commentaires ·
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de trentm/python-markdown2
Issues similaires
-
New InternshipOuvertenew_internship
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
get_graph warns that the oneway column is missing when no way has a oneway tagPeut-être pris @HTenkanen l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
cython/cython#8110 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
fix: security 🔐 style: article/section 📝 system: data-mgmt 🗃️ system: security 🔐 system: software 💻
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
uabrc/uabrc.github.io#1267 ·
-
Link Checker ReportOuverteBot Type: Bug Type: Documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour