mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #8462 -- Made length and length_is template filters fail silently when given a value that has undefined length and added tests for both filters.  Based on patch from marcelor, rob, and SmileyChris.
				
					
				
			git-svn-id: http://code.djangoproject.com/svn/django/trunk@10193 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -515,12 +515,18 @@ last.is_safe = True | ||||
|  | ||||
| def length(value): | ||||
|     """Returns the length of the value - useful for lists.""" | ||||
|     return len(value) | ||||
|     try: | ||||
|         return len(value) | ||||
|     except (ValueError, TypeError): | ||||
|         return '' | ||||
| length.is_safe = True | ||||
|  | ||||
| def length_is(value, arg): | ||||
|     """Returns a boolean of whether the value's length is the argument.""" | ||||
|     return len(value) == int(arg) | ||||
|     try: | ||||
|         return len(value) == int(arg) | ||||
|     except (ValueError, TypeError): | ||||
|         return '' | ||||
| length_is.is_safe = False | ||||
|  | ||||
| def random(value): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user