Fixed #7557 -- Added type checking to Variable initialization.
Thanks tobias for the suggestion and boblefrag and saz for work on the patch.
This commit is contained in:
parent
55b9bff07f
commit
7fec5a2240
|
@ -675,6 +675,9 @@ class Variable(object):
|
||||||
self.translate = False
|
self.translate = False
|
||||||
self.message_context = None
|
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:
|
try:
|
||||||
# First try to treat this variable as a number.
|
# First try to treat this variable as a number.
|
||||||
#
|
#
|
||||||
|
|
|
@ -87,6 +87,10 @@ class ParserTests(TestCase):
|
||||||
Variable, "article._hidden"
|
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)
|
@override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
|
||||||
def test_compile_filter_error(self):
|
def test_compile_filter_error(self):
|
||||||
# regression test for #19819
|
# regression test for #19819
|
||||||
|
|
Loading…
Reference in New Issue