Skip to content

Escape quotes in MarkdownRenderer link and image titles#459

Merged
lepture merged 1 commit into
lepture:mainfrom
sarathfrancis90:fix/markdown-renderer-link-title-quote
Jun 27, 2026
Merged

Escape quotes in MarkdownRenderer link and image titles#459
lepture merged 1 commit into
lepture:mainfrom
sarathfrancis90:fix/markdown-renderer-link-title-quote

Conversation

@sarathfrancis90

Copy link
Copy Markdown
Contributor

The MarkdownRenderer wraps link and image titles in double quotes but never escapes a quote inside the title, so a title containing one round-trips into broken Markdown:

>>> md = mistune.create_markdown(renderer=MarkdownRenderer())
>>> md("[t](/u 'a\"b')\n")
'[t](/u "a"b")\n'

Re-parsing that output closes the title at the embedded quote, so the title is silently dropped and the link can fail to parse. Reference-link titles (in render_referrences) and image titles hit the same thing.

I escape backslashes and then the closing quote before writing the title, the same way the renderer already keeps other special characters literal (codespan backticks, leading block markers). Added a round-trip test covering inline links, images and reference links, plus a title mixing a backslash with a quote.

A title containing a double quote was emitted unescaped inside double
quotes, e.g. [t](/u 'a"b') re-rendered as [t](/u "a"b"). On a
re-parse the embedded quote closes the title early, so the title is
silently dropped (or the link fails to parse). Escape backslashes and
the closing quote when writing inline-link, image and reference-link
titles so they survive a round trip.
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.05%. Comparing base (0799e19) to head (2c1a518).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #459   +/-   ##
=======================================
  Coverage   91.04%   91.05%           
=======================================
  Files          34       34           
  Lines        3407     3409    +2     
  Branches      672      672           
=======================================
+ Hits         3102     3104    +2     
  Misses        184      184           
  Partials      121      121           
Flag Coverage Δ
unittests 91.02% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lepture lepture merged commit ecd435a into lepture:main Jun 27, 2026
27 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants