``StrictUndefined`` for the ``in`` operator. :issue:`1448`
- Imported macros have access to the current template globals in async
environments. :issue:`1494`
+- ``PackageLoader`` will not include a current directory (.) path
+ segment. This allows loading templates from the root of a zip
+ import. :issue:`1467`
Version 3.0.1
package_path: "str" = "templates",
encoding: str = "utf-8",
) -> None:
+ package_path = os.path.normpath(package_path).rstrip(os.path.sep)
+
+ # normpath preserves ".", which isn't valid in zip paths.
if package_path == os.path.curdir:
package_path = ""
elif package_path[:2] == os.path.curdir + os.path.sep:
package_path = package_path[2:]
- package_path = os.path.normpath(package_path).rstrip(os.path.sep)
self.package_path = package_path
self.package_name = package_name
self.encoding = encoding
assert package_zip_loader.list_templates() == ["foo/test.html", "test.html"]
+@pytest.mark.parametrize("package_path", ["", ".", "./"])
+def test_package_zip_omit_curdir(package_zip_loader, package_path):
+ """PackageLoader should not add or include "." or "./" in the root
+ path, it is invalid in zip paths.
+ """
+ loader = PackageLoader("t_pack", package_path)
+ assert loader.package_path == ""
+ source, _, _ = loader.get_source(None, "templates/foo/test.html")
+ assert source.rstrip() == "FOO"
+
+
def test_pep_451_import_hook():
class ImportHook(importlib.abc.MetaPathFinder, importlib.abc.Loader):
def find_spec(self, name, path=None, target=None):