Ticket #3465: 3465_2.diff
File 3465_2.diff, 3.2 KB (added by , 18 years ago) |
---|
-
django/template/__init__.py
=== modified file 'django/template/__init__.py'
665 665 except (TypeError, AttributeError): 666 666 try: # list-index lookup 667 667 current = current[int(bits[0])] 668 except (IndexError, ValueError, KeyError): 668 except (IndexError, # list index out of range 669 ValueError, # invalid literal for int() 670 KeyError, # current is a dict without `int(bits[0])` key 671 TypeError, # unsubscriptable object 672 ): 669 673 raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bits[0], current)) # missing attribute 670 674 except Exception, e: 671 675 if getattr(e, 'silent_variable_failure', False): -
tests/regressiontests/templates/tests.py
=== modified file 'tests/regressiontests/templates/tests.py'
127 127 # Fail silently when accessing a non-simple method 128 128 'basic-syntax20': ("{{ var.method2 }}", {"var": SomeClass()}, ("","INVALID")), 129 129 130 # List-index syntax allows a template to access a certain item of a subscriptable object. 131 'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"), 132 133 # Fail silently when the list index is out of range. 134 'list-index02': ("{{ var.5 }}", {"var": ["first item", "second item"]}, ("", "INVALID")), 135 136 # Fail silently when the variable is not a subscriptable object. 137 'list-index03': ("{{ var.1 }}", {"var": None}, ("", "INVALID")), 138 139 # Fail silently when variable is a dict without the specified key. 140 'list-index04': ("{{ var.1 }}", {"var": {}}, ("", "INVALID")), 141 142 # Dictionary lookup wins out when dict's key is a string. 143 'list-index05': ("{{ var.1 }}", {"var": {'1': "hello"}}, "hello"), 144 145 # But list-index lookup wins out when dict's key is an int, which 146 # behind the scenes is really a dictionary lookup (for a dict) 147 # after converting the key to an int. 148 'list-index06': ("{{ var.1 }}", {"var": {1: "hello"}}, "hello"), 149 150 # Dictionary lookup wins out when there is a string and int version of the key. 151 'list-index07': ("{{ var.1 }}", {"var": {'1': "hello", 1: "world"}}, "hello"), 152 130 153 # Basic filter usage 131 154 'basic-syntax21': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"), 132 155 … … 167 190 'basic-syntax33': (r'1{{ var.method3 }}2', {"var": SomeClass()}, ("12", "1INVALID2")), 168 191 169 192 # In methods that raise an exception without a "silent_variable_attribute" set to True, 170 # the exception prop ogates193 # the exception propagates 171 194 'basic-syntax34': (r'1{{ var.method4 }}2', {"var": SomeClass()}, SomeOtherException), 172 195 173 196 # Escaped backslash in argument