1
0
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:
Gary Wilson Jr
2009-03-30 16:46:27 +00:00
parent a6d7b418de
commit 432f7f624a
2 changed files with 31 additions and 5 deletions

View File

@@ -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):