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, fix #1028, and fix #1116.

`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.
@smipi1
Copy link
Copy Markdown

smipi1 commented Apr 23, 2026

Hi @mb ,

What is still needed to get this upstream? Can I assist?

@mb
Copy link
Copy Markdown
Author

mb commented Apr 23, 2026

Review from maintainers needed. Not sure if there is anything you can assist with.

I think this patch is good as-is and hopefully includes enough test coverage to make review easy. I'm happy to update the patch if necessary.

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

Labels

None yet

Projects

None yet

2 participants