Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 FIX: Double encoded ampersands in query params #929

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sumezulike
Copy link
Contributor

This closes #760.

MyST already escapes the & in the query params, but docutils escapes them again when rendering HTML, leading to broken query params.

[Link](example.com?foo=1&bar=2)

becomes

<p><a href="example.com?foo=1&amp;amp;bar=2">Link</a></p>

instead of

<p><a href="example.com?foo=1&amp;bar=2">Link</a></p>

These changes to the docutils parser override the HTMLTranslator.encode function so already encoded ampersands are not encoded again.
Since the issue lies in the interaction with docutils, I think it makes sense to fix it here.
Also, simply removing the escapeHtml call in MyST makes the sphinx app doctree XML files invalid because the ampersands aren't escaped.

@codecov-commenter
Copy link

codecov-commenter commented May 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.15%. Comparing base (3d84ff8) to head (1151bee).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #929      +/-   ##
==========================================
+ Coverage   90.13%   90.15%   +0.02%     
==========================================
  Files          24       24              
  Lines        3416     3423       +7     
==========================================
+ Hits         3079     3086       +7     
  Misses        337      337              
Flag Coverage Δ
pytests 90.15% <100.00%> (+0.02%) ⬆️

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

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

Comment on lines +272 to +275
HTMLTranslator.special_chars_no_amp = { # needed by encode_fixed
k: v for k, v in HTMLTranslator.special_characters.items() if k != ord("&")
}
HTMLTranslator.encode = encode_fixed
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid this is not something that cannot be merged; it would break restructuredtext parsing.

Monkey patching is done strictly as a last resort, and only for where the patch does not affect upstream use

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.

Unable to link with multiple query params
3 participants