Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #7557 -- Added type checking to Variable initialization.

Thanks tobias for the suggestion and boblefrag and saz for work on the
patch.
  • Loading branch information...
commit 7fec5a2240835af7c7f3accd64d9d894d4f92782 1 parent 55b9bff
@timgraham timgraham authored
Showing with 7 additions and 0 deletions.
  1. +3 −0  django/template/base.py
  2. +4 −0 tests/template_tests/test_parser.py
View
3  django/template/base.py
@@ -675,6 +675,9 @@ def __init__(self, var):
self.translate = False
self.message_context = None
+ if not isinstance(var, six.string_types):
+ raise TypeError(
+ "Variable must be a string or number, got %s" % type(var))
try:
# First try to treat this variable as a number.
#
View
4 tests/template_tests/test_parser.py
@@ -87,6 +87,10 @@ def test_variable_parsing(self):
Variable, "article._hidden"
)
+ # Variables should raise on non string type
+ with six.assertRaisesRegex(self, TypeError, "Variable must be a string or number, got <(class|type) 'dict'>"):
+ Variable({})
+
@override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
def test_compile_filter_error(self):
# regression test for #19819
Please sign in to comment.
Something went wrong with that request. Please try again.