Skip to content

Commit

Permalink
use posixpath.join when loading template names
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Mar 15, 2022
1 parent 3a050b1 commit c552b63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/jinja2/loaders.py
Expand Up @@ -3,6 +3,7 @@
"""
import importlib.util
import os
import posixpath
import sys
import typing as t
import weakref
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c552b63

Please sign in to comment.