Skip to content

🐛 FIX: Correctly encode "&" in Markdown URLs by not HTML-escaping refuri#1126

Open
mb wants to merge 1 commit intoexecutablebooks:masterfrom
mb:ampersand
Open

🐛 FIX: Correctly encode "&" in Markdown URLs by not HTML-escaping refuri#1126
mb wants to merge 1 commit intoexecutablebooks:masterfrom
mb:ampersand

Conversation

@mb
Copy link
Copy Markdown

@mb mb commented Apr 13, 2026

escapeHtml was called on the URL before storing it in the refuri attribute of a reference node, converting & to &. This caused double-escaping when Sphinx's HTML writer later escaped the & in & to produce & in the final href attribute, breaking URLs with query parameters.

The refuri attribute should hold the raw URL; HTML-escaping is the responsibility of the output writer. The other characters escapeHtml converts (<, >, ") are already percent-encoded by normalizeLink before reaching this point, so removing the call has no other effect.

Found while taking a look at https://bugzilla.mozilla.org/show_bug.cgi?id=2023603.

Discovered that there exist a similar patch shortly before creating this pull request. So this is an alternative approach to #929. I've imported the tests from the other patch to verify that the patch behaves the same.

Would fix #760 and fix #1028.

`escapeHtml` was called on the URL before storing it in the `refuri`
attribute of a reference node, converting `&` to `&amp;`. This caused
double-escaping when Sphinx's HTML writer later escaped the `&` in
`&amp;` to produce `&amp;amp;` in the final `href` attribute, breaking
URLs with query parameters.

The `refuri` attribute should hold the raw URL; HTML-escaping is the
responsibility of the output writer. The other characters `escapeHtml`
converts (`<`, `>`, `"`) are already percent-encoded by `normalizeLink`
before reaching this point, so removing the call has no other effect.
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.

Double escaped & in HTML link query params with Sphinx and MyST Unable to link with multiple query params

1 participant