summaryrefslogtreecommitdiff
path: root/django/templatetags
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2020-09-26 15:03:13 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-29 08:03:51 +0200
commit01a7af09b9d61aa66f5bf345fc32cc8f90ecb62a (patch)
tree47c31ccdf1d1c51d3a92fa229ef646840cabdc4d /django/templatetags
parent848770dd2c5dec6c805d67f470eb936f38b9421d (diff)
Fixed #18995 -- Made blocktranslate tag raise TemplateSyntaxError when plural count is not a number.
Diffstat (limited to 'django/templatetags')
-rw-r--r--django/templatetags/i18n.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py
index d0fda0797e..93023f3109 100644
--- a/django/templatetags/i18n.py
+++ b/django/templatetags/i18n.py
@@ -1,3 +1,5 @@
+from decimal import Decimal
+
from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError, Variable
from django.template.base import TokenType, render_value_in_context
@@ -135,6 +137,11 @@ class BlockTranslateNode(Node):
singular, vars = self.render_token_list(self.singular)
if self.plural and self.countervar and self.counter:
count = self.counter.resolve(context)
+ if not isinstance(count, (Decimal, float, int)):
+ raise TemplateSyntaxError(
+ "%r argument to %r tag must be a number."
+ % (self.countervar, self.tag_name)
+ )
context[self.countervar] = count
plural, plural_vars = self.render_token_list(self.plural)
if message_context: