Merge branch '3.1.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents e542e10, 7f66a58 · Browse files · 3 files·+28 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+28 added−7 removed
- tests:+12 added−4 removed
- other:+16 added−3 removed
Provenance
- Commit
6f79daa- Tree
9ca03b9- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
e542e10- Parent 2
7f66a58
3 files changed+28 added−7 removed
modified:src/jinja2/loaders.py+7 added-3 removed
211 unmodified lines212 return os.path.getmtime(filename) == mtime213 except OSError:214 return False215 216- return contents, filename, uptodate216+ # Use normpath to convert Windows altsep to sep.217+ return contents, os.path.normpath(filename), uptodate218 raise TemplateNotFound(template)219 220 def list_templates(self) -> t.List[str]:221 found = set()108 unmodified lines330 def get_source(331 self, environment: "Environment", template: str332 ) -> t.Tuple[str, str, t.Optional[t.Callable[[], bool]]]:333 # Use posixpath even on Windows to avoid "drive:" or UNC333- # segments breaking out of the search directory.334- p = posixpath.join(self._template_root, *split_template_path(template))334+ # segments breaking out of the search directory. Use normpath to335+ # convert Windows altsep to sep.336+ p = os.path.normpath(337+ posixpath.join(self._template_root, *split_template_path(template))338+ )339 up_to_date: t.Optional[t.Callable[[], bool]]340 341 if self._archive is None:342 # Package is a directory.319 unmodified linesmodified:tests/test_loader.py+12 added-4 removed
1 unmodified line2 import importlib.machinery3 import importlib.util4 import os5 import platform6-import posixpath6 import shutil7 import sys8 import tempfile9 import time160 unmodified lines170 e = Environment(loader=loader)171 t = e.get_template("mojibake.txt")172 assert t.render() == expect173 174+ def test_filename_normpath(self):175+ """Nested template names should only contain ``os.sep`` in the176+ loaded filename.177+ """178+ loader = loaders.FileSystemLoader(self.searchpath)179+ e = Environment(loader=loader)180+ t = e.get_template("foo/test.html")181+ assert t.filename == str(self.searchpath / "foo" / "test.html")182 183+184 class TestModuleLoader:185 archive = None186 187 def compile_down(self, prefix_loader, zip="deflated"):123 unmodified lines311 )312 def test_package_dir_source(package_dir_loader, template, expect):313 source, name, up_to_date = package_dir_loader.get_source(None, template)314 assert source.rstrip() == expect307- assert name.endswith(posixpath.join(*split_template_path(template)))315+ assert name.endswith(os.path.join(*split_template_path(template)))316 assert up_to_date()317 318 319 def test_package_dir_list(package_dir_loader):13 unmodified lines333 )334 def test_package_file_source(package_file_loader, template, expect):335 source, name, up_to_date = package_file_loader.get_source(None, template)336 assert source.rstrip() == expect329- assert name.endswith(posixpath.join(*split_template_path(template)))337+ assert name.endswith(os.path.join(*split_template_path(template)))338 assert up_to_date()339 340 341 def test_package_file_list(package_file_loader):14 unmodified lines356 )357 def test_package_zip_source(package_zip_loader, template, expect):358 source, name, up_to_date = package_zip_loader.get_source(None, template)359 assert source.rstrip() == expect352- assert name.endswith(posixpath.join(*split_template_path(template)))360+ assert name.endswith(os.path.join(*split_template_path(template)))361 assert up_to_date is None362 363 364 @pytest.mark.xfail(48 unmodified linesmodified:CHANGES.rst+9 added
4 unmodified lines5 6 Unreleased7 8 9+Version 3.1.110+-------------11+12+Released 2022-03-2513+14+- The template filename on Windows uses the primary path separator.15+ :issue:`1637`16+17+18 Version 3.1.019 -------------20 21 Released 2022-03-24950 unmodified lines