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

Double escaped & in HTML link query params with Sphinx and MyST #1028

Open
palotasb opened this issue Feb 25, 2025 · 0 comments
Open

Double escaped & in HTML link query params with Sphinx and MyST #1028

palotasb opened this issue Feb 25, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@palotasb
Copy link

What version of myst-parser are you using?

4.0.1

What version dependencies are you using?

The latest as of today.

Package                       Version
----------------------------- ---------
alabaster                     1.0.0
babel                         2.17.0
certifi                       2025.1.31
charset-normalizer            3.4.1
docutils                      0.21.2
idna                          3.10
imagesize                     1.4.1
jinja2                        3.1.5
markdown-it-py                3.0.0
markupsafe                    3.0.2
mdit-py-plugins               0.4.2
mdurl                         0.1.2
myst-parser                   4.0.1
packaging                     24.2
pygments                      2.19.1
pyyaml                        6.0.2
requests                      2.32.3
roman-numerals-py             3.1.0
snowballstemmer               2.2.0
sphinx                        8.2.1
sphinxcontrib-applehelp       2.0.0
sphinxcontrib-devhelp         2.0.0
sphinxcontrib-htmlhelp        2.1.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          2.0.0
sphinxcontrib-serializinghtml 2.0.0
urllib3                       2.3.0

What operating system are you using?

Mac

Describe the Bug

Creating a link such as the following:

[Test link.](https://example.org/?a=1&b=2)

Produces the following incorrect HTML.

<p><a class="reference external" href="https://example.org/?a=1&amp;amp;b=2">Test link.</a></p>

Note how the & separating the parameters is double-escaped into &amp;amp;.

Expected Behavior

The same output should produce the following HTML.

<p><a class="reference external" href="https://example.org/?a=1&amp;b=2">Test link.</a></p>

To Reproduce

This is a possible duplicate of #760 which is labeled as more-info-required. A possible fix (unverified by me) is at #929.


To reproduce the issue:

Create the following files in an empty directory.

pyproject.toml:

[project]
name = "test-sphinx-amp-mcve"
version = "1"

dependencies = [
    "sphinx",
    "myst-parser",
]

docs/conf.py:

extensions = ["myst_parser"]

docs/index.md:

# Test page

[Test link.](https://example.org/?a=1&b=2)

Install dependencies via uv or any other package manager:

uv venv
. ./venv/bin/activate
uv sync --upgrade --exclude-newer=2025-02-25T14:50:00+01:00

(The last parameter ensures you get the exact same packages as me right now. Omit it to reproduce with newer dependency version in the future.)

Build the docs using Sphinx:

sphinx-build "docs" "docs/build"

Observe the output.

$ grep '1&amp;' --color=always docs/build/index.html
<p><a class="reference external" href="https://example.org/?a=1&amp;amp;b=2">Test link.</a></p>
@palotasb palotasb added the bug Something isn't working label Feb 25, 2025
@palotasb palotasb changed the title Links with multiple parameters produces incorrect HTML with Sphinx Double escaped & in HTML link query params with Sphinx and MyST Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant