mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
Fixed #28502 -- Made stringformat template filter accept tuples
This commit is contained in:
parent
9229e005aa
commit
4ead705cb3
@ -224,6 +224,8 @@ def stringformat(value, arg):
|
||||
for documentation of Python string formatting.
|
||||
"""
|
||||
try:
|
||||
if isinstance(value, tuple):
|
||||
return ('%' + str(arg)) % str(value)
|
||||
return ("%" + str(arg)) % value
|
||||
except (ValueError, TypeError):
|
||||
return ""
|
||||
|
@ -30,6 +30,8 @@ class FunctionTests(SimpleTestCase):
|
||||
def test_format(self):
|
||||
self.assertEqual(stringformat(1, '03d'), '001')
|
||||
self.assertEqual(stringformat([1, None], 's'), '[1, None]')
|
||||
self.assertEqual(stringformat((1, 2, 3), 's'), '(1, 2, 3)')
|
||||
self.assertEqual(stringformat((1,), 's'), '(1,)')
|
||||
self.assertEqual(stringformat({1, 2}, 's'), '{1, 2}')
|
||||
self.assertEqual(stringformat({1: 2, 2: 3}, 's'), '{1: 2, 2: 3}')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user