Skip to content

Fix a panic on email addresses in image titles with GFM - #263

Open
ChristianMurphy wants to merge 1 commit into
wooorm:mainfrom
ChristianMurphy:fix/gfm-autolink-literal-in-title
Open

ChristianMurphy wants to merge 1 commit into
wooorm:mainfrom
ChristianMurphy:fix/gfm-autolink-literal-in-title

Conversation

@ChristianMurphy

Copy link
Copy Markdown
Collaborator

Summary

With GFM, an email address in an image title that spans lines panics in 1.0.0:

markdown::to_html_with_options("![a](b \"c@d.com\ne\")", &markdown::Options::gfm()); // Option::unwrap() on None, src/subtokenize.rs:218

CommonMark renders <p><img src="b" alt="a" title="c@d.com\ne" /></p>, and GFM doesn't autolink in titles.

The GFM autolink literal resolver scans Data outside links for email addresses and rewrites it into autolinks. It skipped Data inside a Link, but not inside an Image. So it also rewrote image title chunks, which are string content and point to the next chunk through their link field. The rewrite dropped that field, and divide_events panicked. This skips Data that has a link, the same check #207 adds to resolve_whitespace.

Output changes

Single-line image titles change too. 1.0.0 rewrote them, which could escape a character reference twice: ![a](b "c@d.com &amp; e") gave the title c@d.com &amp;amp; e. It is now c@d.com &amp; e, as micromark-extension-gfm gives it.

Performance

Callgrind, with one codegen unit, against 1.0.0 built the same way, across 7 option sets. On small documents, instructions change by −0.6% to +0.2%, within the noise of this method.

Tests

As of 2026-09-29, CI on main fails for two reasons unrelated to this change. One is a new clippy lint on Rust 1.98, and the other is the swc/serde build break. #230 fixes both.

Claude, an AI assistant, helped me build this, and I reviewed it.

Problem: the literal autolink resolver rewrote `Data` inside images,
including linked title chunks, which are string content. In a title
that spans lines, the rewrite dropped the links, and `divide_events`
panicked.

Changes:
- Skip `Data` that carries a link.
- Tests for a title that spans lines and one on a single line.

@Murderlon Murderlon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I authorized Codex to review this PR on my behalf.

No findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants