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 #8959: using UNIX path separator confuses Sphinx on Windows #8967

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Deprecated
Features added
--------------

* #8959: using UNIX path separator in image directive confuses Sphinx on Windows

Bugs fixed
----------

Expand Down
5 changes: 3 additions & 2 deletions sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import os
import pickle
import posixpath
import warnings
from collections import defaultdict
from copy import copy
Expand All @@ -34,6 +33,7 @@
from sphinx.util.docutils import LoggingReporter
from sphinx.util.i18n import CatalogRepository, docname_to_domain
from sphinx.util.nodes import is_translatable
from sphinx.util.osutil import canon_path, os_path

if False:
# For type annotation
Expand Down Expand Up @@ -351,14 +351,15 @@ def relfn2path(self, filename: str, docname: str = None) -> Tuple[str, str]:
source dir, while relative filenames are relative to the dir of the
containing document.
"""
filename = os_path(filename)
if filename.startswith('/') or filename.startswith(os.sep):
rel_fn = filename[1:]
else:
docdir = path.dirname(self.doc2path(docname or self.docname,
base=None))
rel_fn = path.join(docdir, filename)

return (posixpath.normpath(rel_fn),
return (canon_path(path.normpath(rel_fn)),
path.normpath(path.join(self.srcdir, rel_fn)))

@property
Expand Down
10 changes: 4 additions & 6 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from docutils import nodes

from sphinx.errors import SphinxError
from sphinx.testing.path import path


def request_session_head(url, **kwargs):
Expand Down Expand Up @@ -137,17 +136,16 @@ def test_image_glob(app, status, warning):
doctree = app.env.get_doctree('subdir/index')

assert isinstance(doctree[0][1], nodes.image)
sub = path('subdir')
assert doctree[0][1]['candidates'] == {'*': sub / 'rimg.png'}
assert doctree[0][1]['uri'] == sub / 'rimg.png'
assert doctree[0][1]['candidates'] == {'*': 'subdir/rimg.png'}
assert doctree[0][1]['uri'] == 'subdir/rimg.png'

assert isinstance(doctree[0][2], nodes.image)
assert doctree[0][2]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'}
assert doctree[0][2]['uri'] == sub / 'svgimg.*'
assert doctree[0][2]['uri'] == 'subdir/svgimg.*'

assert isinstance(doctree[0][3], nodes.figure)
assert isinstance(doctree[0][3][0], nodes.image)
assert doctree[0][3][0]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'}
assert doctree[0][3][0]['uri'] == sub / 'svgimg.*'
assert doctree[0][3][0]['uri'] == 'subdir/svgimg.*'