Permalink
Browse files

Fixed #21959 -- Handled Inf/NaN in widthratio tag.

Thanks rmoe for the report and the patch.
  • Loading branch information...
1 parent 5d263de commit 07ae47f7f8b5d5f80238ea3018163cad12917852 @aaugustin aaugustin committed Feb 8, 2014
Showing with 4 additions and 2 deletions.
  1. +2 −2 django/template/defaulttags.py
  2. +2 −0 tests/template_tests/tests.py
@@ -498,11 +498,11 @@ def render(self, context):
value = float(value)
max_value = float(max_value)
ratio = (value / max_value) * max_width
+ result = str(int(round(ratio)))
except ZeroDivisionError:
return '0'
- except (ValueError, TypeError):
+ except (ValueError, TypeError, OverflowError):
return ''
- result = str(int(round(ratio)))
if self.asvar:
context[self.asvar] = result
@@ -1668,6 +1668,8 @@ def get_template_tests(self):
'widthratio18': ('{% widthratio a b 100 as %}', {}, template.TemplateSyntaxError),
'widthratio19': ('{% widthratio a b 100 not_as variable %}', {}, template.TemplateSyntaxError),
+ 'widthratio20': ('{% widthratio a b 100 %}', {'a': float('inf'), 'b': float('inf')}, ''),
+ 'widthratio21': ('{% widthratio a b 100 %}', {'a': float('inf'), 'b': 2}, ''),
### WITH TAG ########################################################
'with01': ('{% with key=dict.key %}{{ key }}{% endwith %}', {'dict': {'key': 50}}, '50'),

2 comments on commit 07ae47f

Currently i am using 1.5.5 and it getting crashed. This change helped me to fix the crash.
Thanks :-)
Can you please tell me In which version of django is this patch updated.
Is it 1.5.6 or above

Contributor

Version 1.7 is the only version that has this.

Please sign in to comment.