|
3 | 3 | """
|
4 | 4 | import importlib.util
|
5 | 5 | import os
|
| 6 | +import posixpath |
6 | 7 | import sys
|
7 | 8 | import typing as t
|
8 | 9 | import weakref
|
@@ -193,7 +194,9 @@ def get_source(
|
193 | 194 | ) -> t.Tuple[str, str, t.Callable[[], bool]]:
|
194 | 195 | pieces = split_template_path(template)
|
195 | 196 | for searchpath in self.searchpath:
|
196 |
| - filename = os.path.join(searchpath, *pieces) |
| 197 | + # Use posixpath even on Windows to avoid "drive:" or UNC |
| 198 | + # segments breaking out of the search directory. |
| 199 | + filename = posixpath.join(searchpath, *pieces) |
197 | 200 | f = open_if_exists(filename)
|
198 | 201 | if f is None:
|
199 | 202 | continue
|
@@ -296,7 +299,7 @@ def __init__(
|
296 | 299 | if isinstance(loader, zipimport.zipimporter):
|
297 | 300 | self._archive = loader.archive
|
298 | 301 | pkgdir = next(iter(spec.submodule_search_locations)) # type: ignore
|
299 |
| - template_root = os.path.join(pkgdir, package_path) |
| 302 | + template_root = os.path.join(pkgdir, package_path).rstrip(os.path.sep) |
300 | 303 | else:
|
301 | 304 | roots: t.List[str] = []
|
302 | 305 |
|
@@ -326,7 +329,9 @@ def __init__(
|
326 | 329 | def get_source(
|
327 | 330 | self, environment: "Environment", template: str
|
328 | 331 | ) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]:
|
329 |
| - p = os.path.join(self._template_root, *split_template_path(template)) |
| 332 | + # Use posixpath even on Windows to avoid "drive:" or UNC |
| 333 | + # segments breaking out of the search directory. |
| 334 | + p = posixpath.join(self._template_root, *split_template_path(template)) |
330 | 335 | up_to_date: t.Optional[t.Callable[[], bool]]
|
331 | 336 |
|
332 | 337 | if self._archive is None:
|
|
0 commit comments