From 624573726aa5982d1c73aac85fb27aea3b3b23b7 Mon Sep 17 00:00:00 2001 From: Nathan Gaberel Date: Sat, 23 Mar 2019 20:27:45 +0000 Subject: [PATCH] Fixed #29791 -- Made Engine.render_to_string() honor autoescape. --- AUTHORS | 1 + django/template/engine.py | 2 +- tests/template_tests/test_engine.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 01908ad6c9..c8054c9e20 100644 --- a/AUTHORS +++ b/AUTHORS @@ -627,6 +627,7 @@ answer newbie questions, and generally made Django that much better: Nasir Hussain Natalia Bidart Nate Bragg + Nathan Gaberel Neal Norwitz Nebojša Dorđević Ned Batchelder diff --git a/django/template/engine.py b/django/template/engine.py index dfaa67ba12..ff9ce58d59 100644 --- a/django/template/engine.py +++ b/django/template/engine.py @@ -160,7 +160,7 @@ class Engine: if isinstance(context, Context): return t.render(context) else: - return t.render(Context(context)) + return t.render(Context(context, autoescape=self.autoescape)) def select_template(self, template_name_list): """ diff --git a/tests/template_tests/test_engine.py b/tests/template_tests/test_engine.py index 2bb8601fbb..b975ea87b4 100644 --- a/tests/template_tests/test_engine.py +++ b/tests/template_tests/test_engine.py @@ -21,6 +21,13 @@ class RenderToStringTest(SimpleTestCase): 'obj:test\n', ) + def test_autoescape_off(self): + engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False) + self.assertEqual( + engine.render_to_string('test_context.html', {'obj': '