Skip to content

Double slashes when generating the inventory file URL #12782

@replaceafill

Description

@replaceafill

Describe the bug

This might be considered an edge case but I've noticed that if the value tuple of a intersphinx_mapping contains a base URI with a trailing slash and None as the inventory file, Sphinx will try to load a URL with double slashes.

How to Reproduce

Using Sphinx 8.0.2 set the following in the conf.py file of a sphinx-quickstart project:

extensions = ["sphinx.ext.intersphinx"]
intersphinx_mapping = {'python': ('https://docs.python.org/3/', None)}

Run make html and notice the double slashes in the output message:

...
loading intersphinx inventory 'python' from https://docs.python.org/3//objects.inv ...
...

The double slashes URL could be problematic depending on the web server setup.

Environment Information

Platform:              linux; (Linux-6.5.0-45-generic-x86_64-with-glibc2.35)
Python version:        3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0])
Python implementation: CPython
Sphinx version:        8.0.2
Docutils version:      0.21.2
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

["sphinx.ext.intersphinx"]

Additional context

I think the problem could have been introduced in #12087 where:

if not inv:
inv = posixpath.join(uri, INVENTORY_FILENAME)

was changed into:

inv = f'{project.target_uri}/{INVENTORY_FILENAME}' if location is None else location

posixpath.join removes the trailing slash in the target URI, but the f-string doesn't.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions