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

Support Windows UNC paths in loaders #1913

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/jinja2/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import importlib.util
import os
import pathlib
import posixpath
import sys
import typing as t
Expand Down Expand Up @@ -198,7 +199,8 @@ def get_source(
for searchpath in self.searchpath:
# Use posixpath even on Windows to avoid "drive:" or UNC
# segments breaking out of the search directory.
filename = posixpath.join(searchpath, *pieces)
# Normalize path separators after that using pathlib.
filename = str(pathlib.Path(posixpath.join(searchpath, *pieces)))

if os.path.isfile(filename):
break
Expand Down Expand Up @@ -333,10 +335,12 @@ def get_source(
self, environment: "Environment", template: str
) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]:
# Use posixpath even on Windows to avoid "drive:" or UNC
# segments breaking out of the search directory. Use normpath to
# convert Windows altsep to sep.
p = os.path.normpath(
posixpath.join(self._template_root, *split_template_path(template))
# segments breaking out of the search directory.
# Normalize path separators after that using pathlib.
p = str(
pathlib.Path(
posixpath.join(self._template_root, *split_template_path(template))
)
)
up_to_date: t.Optional[t.Callable[[], bool]]

Expand Down