From a8f35bb4631a71b65c44a01047b9a6023363ce77 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 18 Jan 2024 22:19:58 +0100 Subject: [PATCH] Do not use query components in URLs for assets in EPUB rendering (#11766) Signed-off-by: David Runge Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- CHANGES.rst | 2 ++ sphinx/builders/html/__init__.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f28248a3c..563efe5de 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -70,6 +70,8 @@ Bugs fixed Patch by James Addison. * #11886: Print the Jinja2 template path chain in ``TemplateNotFound`` exceptions. Patch by Colin Marquardt. +* #11598: Do not use query components in URLs for assets in EPUB rendering. + Patch by David Runge. Testing ------- diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 287bb79ce..e14b7c10e 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -1051,8 +1051,10 @@ class StandaloneHTMLBuilder(Builder): for key, value in css.attributes.items() if value is not None] uri = pathto(os.fspath(css.filename), resource=True) - if checksum := _file_checksum(outdir, css.filename): - uri += f'?v={checksum}' + # the EPUB format does not allow the use of query components + if self.name != 'epub': + if checksum := _file_checksum(outdir, css.filename): + uri += f'?v={checksum}' return f'' ctx['css_tag'] = css_tag @@ -1079,8 +1081,10 @@ class StandaloneHTMLBuilder(Builder): # https://docs.mathjax.org/en/v2.7-latest/configuration.html#considerations-for-using-combined-configuration-files # https://github.com/sphinx-doc/sphinx/issues/11658 pass - elif checksum := _file_checksum(outdir, js.filename): - uri += f'?v={checksum}' + # the EPUB format does not allow the use of query components + elif self.name != 'epub': + if checksum := _file_checksum(outdir, js.filename): + uri += f'?v={checksum}' if attrs: return f'' return f''