Skip to content

Commit

Permalink
Fixed #29791 -- Made Engine.render_to_string() honor autoescape.
Browse files Browse the repository at this point in the history
  • Loading branch information
n6g7 authored and timgraham committed Mar 25, 2019
1 parent d4df5e1 commit 6245737
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ answer newbie questions, and generally made Django that much better:
Nasir Hussain <[email protected]>
Natalia Bidart <[email protected]>
Nate Bragg <[email protected]>
Nathan Gaberel <[email protected]>
Neal Norwitz <[email protected]>
Nebojša Dorđević
Ned Batchelder <https://nedbatchelder.com/>
Expand Down
2 changes: 1 addition & 1 deletion django/template/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def render_to_string(self, template_name, context=None):
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):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/template_tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def test_basic_context(self):
'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': '<script>'}),
'obj:<script>\n',
)


class GetDefaultTests(SimpleTestCase):

Expand Down

0 comments on commit 6245737

Please sign in to comment.