From fd61ce3817251c487fd98c3ed178a8258775329e Mon Sep 17 00:00:00 2001 From: Noam Date: Thu, 25 Jun 2015 13:46:11 +0300 Subject: [PATCH] [1.8.x] Fixed #25031 -- Fixed a regression in the unordered_list template filter. Backport of e291fc4757e952fd4f663d88adca416b016db13e from master --- django/template/defaultfilters.py | 35 +++++++++++-------- docs/releases/1.8.3.txt | 3 ++ .../filter_tests/test_unordered_list.py | 7 ++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 6aefb3cbf2..9324b7fb71 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -681,22 +681,27 @@ def unordered_list(value, autoescape=True): def walk_items(item_list): item_iterator = iter(item_list) - for item in item_iterator: - try: - next_item = next(item_iterator) - except StopIteration: - next_item = None - if not isinstance(next_item, six.string_types): + try: + item = next(item_iterator) + while True: try: - iter(next_item) - except TypeError: - pass - else: - yield item, next_item - continue - yield item, None - if next_item: - yield next_item, None + next_item = next(item_iterator) + except StopIteration: + yield item, None + break + if not isinstance(next_item, six.string_types): + try: + iter(next_item) + except TypeError: + pass + else: + yield item, next_item + item = next(item_iterator) + continue + yield item, None + item = next_item + except StopIteration: + pass def list_formatter(item_list, tabs=1): indent = '\t' * tabs diff --git a/docs/releases/1.8.3.txt b/docs/releases/1.8.3.txt index 3511a258a4..600291d902 100644 --- a/docs/releases/1.8.3.txt +++ b/docs/releases/1.8.3.txt @@ -89,3 +89,6 @@ Bugfixes * Fixed inline forms that use a parent object that has a ``UUIDField`` primary key and a child object that has an ``AutoField`` primary key (:ticket:`24958`). + +* Fixed a regression in the ``unordered_list`` template filter on certain + inputs (:ticket:`25031`). diff --git a/tests/template_tests/filter_tests/test_unordered_list.py b/tests/template_tests/filter_tests/test_unordered_list.py index 77e5bab0c6..4fbc22a657 100644 --- a/tests/template_tests/filter_tests/test_unordered_list.py +++ b/tests/template_tests/filter_tests/test_unordered_list.py @@ -83,6 +83,13 @@ class FunctionTests(SimpleTestCase): '\n\t\n\t\n\t
  • item 2
  • ', ) + def test_nested3(self): + self.assertEqual( + unordered_list(['item 1', 'item 2', ['item 2.1']]), + '\t
  • item 1
  • \n\t
  • item 2\n\t\n\t
  • ', + ) + def test_nested_multiple(self): self.assertEqual( unordered_list(['item 1', ['item 1.1', ['item 1.1.1', ['item 1.1.1.1']]]]),