From 6970438247f2fd7af26e24b398b85bd23985501c Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Thu, 30 Nov 2023 13:32:03 +0000 Subject: [PATCH] Support Windows UNC paths in loaders --- src/jinja2/loaders.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/jinja2/loaders.py b/src/jinja2/loaders.py index 9b479be4e..fe5453118 100644 --- a/src/jinja2/loaders.py +++ b/src/jinja2/loaders.py @@ -3,6 +3,7 @@ """ import importlib.util import os +import pathlib import posixpath import sys import typing as t @@ -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 @@ -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]]