From b4fd9b5ad481c446636befa40cce5a2b5e9799fc Mon Sep 17 00:00:00 2001 From: ryabtsev Date: Sun, 27 May 2018 02:56:51 +0200 Subject: [PATCH] Fixed #29432 -- Allowed passing an integer to the slice template filter. --- django/template/defaultfilters.py | 2 +- tests/template_tests/filter_tests/test_slice.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 2346f50383..ef7ae8679d 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -573,7 +573,7 @@ def slice_filter(value, arg): """ try: bits = [] - for x in arg.split(':'): + for x in str(arg).split(':'): if not x: bits.append(None) else: diff --git a/tests/template_tests/filter_tests/test_slice.py b/tests/template_tests/filter_tests/test_slice.py index 026db3fa7f..1b92776707 100644 --- a/tests/template_tests/filter_tests/test_slice.py +++ b/tests/template_tests/filter_tests/test_slice.py @@ -26,6 +26,9 @@ class FunctionTests(SimpleTestCase): def test_index(self): self.assertEqual(slice_filter('abcdefg', '1'), 'a') + def test_index_integer(self): + self.assertEqual(slice_filter('abcdefg', 1), 'a') + def test_negative_index(self): self.assertEqual(slice_filter('abcdefg', '-1'), 'abcdef')