Permalink
Browse files

Fixed #12070. Fixed a case where var._whatever wasn't raising a Templ…

…ateSyntaxError.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12539 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 7352238 commit fd233f40d1922c6f3d9dd0e5738397bdc4aac9ef @jkocherhans jkocherhans committed Feb 23, 2010
Showing with 15 additions and 2 deletions.
  1. +2 −2 django/template/__init__.py
  2. +13 −0 tests/regressiontests/templates/parser.py
@@ -538,8 +538,6 @@ def __init__(self, token, parser):
var_obj = None
elif var is None:
raise TemplateSyntaxError("Could not find variable at start of %s." % token)
- elif var.find(VARIABLE_ATTRIBUTE_SEPARATOR + '_') > -1 or var[0] == '_':
- raise TemplateSyntaxError("Variables and attributes may not begin with underscores: '%s'" % var)
else:
var_obj = Variable(var)
else:
@@ -698,6 +696,8 @@ def __init__(self, var):
except ValueError:
# Otherwise we'll set self.lookups so that resolve() knows we're
# dealing with a bonafide variable
+ if var.find(VARIABLE_ATTRIBUTE_SEPARATOR + '_') > -1 or var[0] == '_':
+ raise TemplateSyntaxError("Variables and attributes may not begin with underscores: '%s'" % var)
self.lookups = tuple(var.split(VARIABLE_ATTRIBUTE_SEPARATOR))
def resolve(self, context):
@@ -76,6 +76,13 @@
[]
>>> fe.var
u'Some "Good" News'
+
+Filtered variables should reject access of attributes beginning with underscores.
+
+>>> FilterExpression('article._hidden|upper', p)
+Traceback (most recent call last):
+...
+TemplateSyntaxError: Variables and attributes may not begin with underscores: 'article._hidden'
"""
variable_parsing = r"""
@@ -105,4 +112,10 @@
>>> Variable(ur"'Some \'Better\' News'").resolve(c)
u"Some 'Better' News"
+Variables should reject access of attributes beginning with underscores.
+
+>>> Variable('article._hidden')
+Traceback (most recent call last):
+...
+TemplateSyntaxError: Variables and attributes may not begin with underscores: 'article._hidden'
"""

0 comments on commit fd233f4

Please sign in to comment.