Skip to content

Commit

Permalink
Refs #28502 -- Complemented stringformat tuple handling/test.
Browse files Browse the repository at this point in the history
An additional test and a code change were suggested in a late review.
  • Loading branch information
claudep authored and timgraham committed Aug 22, 2017
1 parent 7bba824 commit ed77bea
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django/template/defaultfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def stringformat(value, arg):
See https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
for documentation of Python string formatting.
"""
if isinstance(value, tuple):
value = str(value)
try:
if isinstance(value, tuple):
return ('%' + str(arg)) % str(value)
return ("%" + str(arg)) % value
except (ValueError, TypeError):
return ""
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/1.11.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Bugfixes
in GEOS 3.6.2) (:ticket:`28441`).

* Fixed test database creation with ``cx_Oracle`` 6 (:ticket:`28498`).

* Fixed select widget rendering when option values are tuples (:ticket:`28502`).
1 change: 1 addition & 0 deletions tests/template_tests/filter_tests/test_stringformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ def test_invalid(self):
self.assertEqual(stringformat(1, 'z'), '')
self.assertEqual(stringformat(object(), 'd'), '')
self.assertEqual(stringformat(None, 'd'), '')
self.assertEqual(stringformat((1, 2, 3), 'd'), '')

0 comments on commit ed77bea

Please sign in to comment.