diff --git a/CHANGES.rst b/CHANGES.rst index 88e167d26..5770effcb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -36,6 +36,9 @@ Unreleased - The ``groupby`` filter is case-insensitive by default, matching other comparison filters. Added the ``case_sensitive`` parameter to control this. :issue:`1463` +- Windows drive-relative path segments in template names will not + result in ``FileSystemLoader`` and ``PackageLoader`` loading from + drive-relative paths. :pr:`1621` Version 3.0.3 diff --git a/src/jinja2/loaders.py b/src/jinja2/loaders.py index d7d9bd042..7ab58249f 100644 --- a/src/jinja2/loaders.py +++ b/src/jinja2/loaders.py @@ -3,6 +3,7 @@ """ import importlib.util import os +import posixpath import sys import typing as t import weakref @@ -193,7 +194,9 @@ def get_source( ) -> t.Tuple[str, str, t.Callable[[], bool]]: pieces = split_template_path(template) for searchpath in self.searchpath: - filename = os.path.join(searchpath, *pieces) + # Use posixpath even on Windows to avoid "drive:" or UNC + # segments breaking out of the search directory. + filename = posixpath.join(searchpath, *pieces) f = open_if_exists(filename) if f is None: continue @@ -326,7 +329,9 @@ def __init__( def get_source( self, environment: "Environment", template: str ) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]: - p = os.path.join(self._template_root, *split_template_path(template)) + # Use posixpath even on Windows to avoid "drive:" or UNC + # segments breaking out of the search directory. + p = posixpath.join(self._template_root, *split_template_path(template)) up_to_date: t.Optional[t.Callable[[], bool]] if self._archive is None: