Ticket #3465: 3465.diff
File 3465.diff, 2.6 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 whin dict's key is an int. 146 'list-index06': ("{{ var.1 }}", {"var": {1: "hello"}}, "hello"), 147 148 # Dictionary lookup wins out when there is a string and int version of the key. 149 'list-index07': ("{{ var.1 }}", {"var": {'1': "hello", 1: "world"}}, "hello"), 150 130 151 # Basic filter usage 131 152 'basic-syntax21': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"), 132 153