From 939632814caaed43cfc7e52bdbd8eb7994ed770f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 25 Nov 2024 02:11:09 -0600 Subject: [PATCH] Disable autoescape in minijinja for YAML rendering --- course/content.py | 6 +++--- relate/bin/relate.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/course/content.py b/course/content.py index 2fa803581..bf24bf906 100644 --- a/course/content.py +++ b/course/content.py @@ -993,7 +993,8 @@ def expand_yaml_macros(repo: Repo_ish, commit_sha: bytes, yaml_str: str) -> str: from minijinja import Environment jinja_env = Environment( loader=YamlBlockEscapingGitTemplateLoader(repo, commit_sha), - undefined_behavior="strict") + undefined_behavior="strict", + auto_escape_callback=lambda fn: False) # {{{ process explicit [JINJA] tags (deprecated) @@ -1099,8 +1100,7 @@ def get_yaml_from_repo( raise ValueError("File uses tabs in indentation. " "This is not allowed.") - expanded = expand_yaml_macros( - repo, commit_sha, yaml_bytestream) + expanded = expand_yaml_macros(repo, commit_sha, yaml_bytestream) yaml_data = load_yaml(expanded) # type:ignore result = dict_to_struct(yaml_data) diff --git a/relate/bin/relate.py b/relate/bin/relate.py index dc7a9ce64..743e84080 100644 --- a/relate/bin/relate.py +++ b/relate/bin/relate.py @@ -86,7 +86,9 @@ def expand_yaml(yml_file, repo_root): from minijinja import Environment jinja_env = Environment( loader=YamlBlockEscapingFileSystemLoader(repo_root), - undefined_behavior="strict") + undefined_behavior="strict", + auto_escape_callback=lambda fn: False, + ) return jinja_env.render_str(data)