summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorGary Wilson Jr <gary.wilson@gmail.com>2009-03-30 16:46:27 +0000
committerGary Wilson Jr <gary.wilson@gmail.com>2009-03-30 16:46:27 +0000
commit432f7f624ac4b6b5fab9a10ae450e71d1f8ecf64 (patch)
treed5e95a7419dd66a1f0611cf15cf353c9e30b54e9 /django
parenta6d7b418dec429bd6d4830ce65ad2b40df6a25e6 (diff)
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
Diffstat (limited to 'django')
-rw-r--r--django/template/defaultfilters.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index ff8d4184ea..cb16e4bbe1 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -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):