Skip to content

Commit 93e8354

Browse files
committed
[1.2.X] Fixed #12965 - unordered_list template filter fails when given a non-iterable second item in a two item list
Thanks to grahamu for the report and patch. Backport of [13845] from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13846 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 21f60e9 commit 93e8354

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

django/template/defaultfilters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ def convert_old_style_list(list_):
601601
first_item, second_item = list_
602602
if second_item == []:
603603
return [first_item], True
604+
try:
605+
it = iter(second_item) # see if second item is iterable
606+
except TypeError:
607+
return list_, False
604608
old_style_list = True
605609
new_second_item = []
606610
for sublist in second_item:

tests/regressiontests/defaultfilters/tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@
347347
>>> unordered_list(['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']])
348348
u'\t<li>States\n\t<ul>\n\t\t<li>Kansas\n\t\t<ul>\n\t\t\t<li>Lawrence</li>\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>\n\t\t<li>Illinois</li>\n\t</ul>\n\t</li>'
349349
350+
>>> class ULItem(object):
351+
... def __init__(self, title):
352+
... self.title = title
353+
... def __unicode__(self):
354+
... return u'ulitem-%s' % str(self.title)
355+
356+
>>> a = ULItem('a')
357+
>>> b = ULItem('b')
358+
>>> unordered_list([a,b])
359+
u'\t<li>ulitem-a</li>\n\t<li>ulitem-b</li>'
360+
350361
# Old format for unordered lists should still work
351362
>>> unordered_list([u'item 1', []])
352363
u'\t<li>item 1</li>'

0 commit comments

Comments
 (0)