Ticket #12070: patch-12070.diff
File patch-12070.diff, 2.1 KB (added by , 15 years ago) |
---|
-
django/template/__init__.py
538 538 var_obj = None 539 539 elif var is None: 540 540 raise TemplateSyntaxError("Could not find variable at start of %s." % token) 541 elif var.find(VARIABLE_ATTRIBUTE_SEPARATOR + '_') > -1 or var[0] == '_':542 raise TemplateSyntaxError("Variables and attributes may not begin with underscores: '%s'" % var)543 541 else: 544 542 var_obj = Variable(var) 545 543 else: … … 698 696 except ValueError: 699 697 # Otherwise we'll set self.lookups so that resolve() knows we're 700 698 # dealing with a bonafide variable 699 if var.find(VARIABLE_ATTRIBUTE_SEPARATOR + '_') > -1 or var[0] == '_': 700 raise TemplateSyntaxError("Variables and attributes may not begin with underscores: '%s'" % var) 701 701 self.lookups = tuple(var.split(VARIABLE_ATTRIBUTE_SEPARATOR)) 702 702 703 703 def resolve(self, context): -
tests/regressiontests/templates/parser.py
76 76 [] 77 77 >>> fe.var 78 78 u'Some "Good" News' 79 80 Filtered variables should reject access of attributes beginning with underscores. 81 82 >>> FilterExpression('article._hidden|upper', p) 83 Traceback (most recent call last): 84 ... 85 TemplateSyntaxError: Variables and attributes may not begin with underscores: 'article._hidden' 79 86 """ 80 87 81 88 variable_parsing = r""" … … 105 112 >>> Variable(ur"'Some \'Better\' News'").resolve(c) 106 113 u"Some 'Better' News" 107 114 115 Variables should reject access of attributes beginning with underscores. 116 117 >>> Variable('article._hidden') 118 Traceback (most recent call last): 119 ... 120 TemplateSyntaxError: Variables and attributes may not begin with underscores: 'article._hidden' 108 121 """