Use SandboxedEnvironment

This commit is contained in:
object-Object 2023-08-23 08:10:10 -04:00
parent 96076c69ac
commit 2fa96babde

View file

@ -7,13 +7,8 @@ from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import Any, Self, Sequence from typing import Any, Self, Sequence
from jinja2 import ( from jinja2 import ChoiceLoader, FileSystemLoader, PackageLoader, StrictUndefined
ChoiceLoader, from jinja2.sandbox import SandboxedEnvironment
Environment,
FileSystemLoader,
PackageLoader,
StrictUndefined,
)
from hexdoc.hexcasting.hex_book import HexContext from hexdoc.hexcasting.hex_book import HexContext
from hexdoc.minecraft.i18n import I18n from hexdoc.minecraft.i18n import I18n
@ -25,9 +20,6 @@ from hexdoc.utils.resource_loader import ModResourceLoader
from .jinja_extensions import IncludeRawExtension, hexdoc_block, hexdoc_wrap from .jinja_extensions import IncludeRawExtension, hexdoc_block, hexdoc_wrap
# TODO: enable
# from jinja2.sandbox import SandboxedEnvironment
def strip_empty_lines(text: str) -> str: def strip_empty_lines(text: str) -> str:
return "\n".join(s for s in text.splitlines() if s.strip()) return "\n".join(s for s in text.splitlines() if s.strip())
@ -105,8 +97,7 @@ def main(args: Args | None = None) -> None:
) )
# set up Jinja environment # set up Jinja environment
# TODO: SandboxedEnvironment env = SandboxedEnvironment(
env = Environment(
# search order: template_dirs, template_packages, built-in hexdoc templates # search order: template_dirs, template_packages, built-in hexdoc templates
loader=ChoiceLoader( loader=ChoiceLoader(
[FileSystemLoader(props.template_dirs)] [FileSystemLoader(props.template_dirs)]