8000
Skip to content

πŸ› FIX: Correctly encode "&" in Markdown URLs by not HTML-escaping refuri - #1126

Merged
chrisjsewell merged 3 commits into
executablebooks:masterfrom
mb:ampersand
May 7, 2026
Merged

πŸ› FIX: Correctly encode "&" in Markdown URLs by not HTML-escaping refuri#1126
chrisjsewell merged 3 commits into
executablebooks:masterfrom
mb:ampersand

Conversation

@mb
@mb mb commented Apr 13, 2026
Copy link
Copy Markdown
Contributor

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
smipi1 commented Apr 23, 2026
Copy link
Copy Markdown

Hi @mb ,

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

@mb
mb commented Apr 23, 2026
Copy link
Copy Markdown
Contributor Author

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.

@chrisjsewell chrisjsewell left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cheers!

@chrisjsewell
chrisjsewell merged commit ca5ac86 into executablebooks:master May 7, 2026
22 checks passed
@smipi1
smipi1 commented May 8, 2026
Copy link
Copy Markdown

Thanks @mb and @chrisjsewell! I really appreciate your efforts to get this fix out.

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

Labels

None yet

Projects

None yet

3 participants

0