mirror of https://github.com/django/django.git
Added test for TemplateSyntaxError when variables begin with underscores.
This commit is contained in:
parent
f03ba0ad52
commit
34d5336b9d
|
@ -79,11 +79,12 @@ class ParserTests(SimpleTestCase):
|
||||||
Variable(r"'Some \'Better\' News'").resolve(c), "Some 'Better' News"
|
Variable(r"'Some \'Better\' News'").resolve(c), "Some 'Better' News"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Variables should reject access of attributes beginning with
|
# Variables should reject access of attributes and variables beginning
|
||||||
# underscores.
|
# with underscores.
|
||||||
msg = "Variables and attributes may not begin with underscores: 'article._hidden'"
|
for name in ['article._hidden', '_article']:
|
||||||
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
msg = f"Variables and attributes may not begin with underscores: '{name}'"
|
||||||
Variable("article._hidden")
|
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||||
|
Variable(name)
|
||||||
|
|
||||||
# Variables should raise on non string type
|
# Variables should raise on non string type
|
||||||
with self.assertRaisesMessage(TypeError, "Variable must be a string or number, got <class 'dict'>"):
|
with self.assertRaisesMessage(TypeError, "Variable must be a string or number, got <class 'dict'>"):
|
||||||
|
|
Loading…
Reference in New Issue