summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-10-23 18:48:24 +0200
committerClaude Paroz <claude@2xlibre.net>2012-10-23 18:49:22 +0200
commit9fd2f9c5f3c008f524874fd7cf78237e65bf567e (patch)
tree048a0b9dcb02dad13751ab788c7c2b9d5491f8b0 /django
parent3541a10d492db6d1f509f3a50a024568c16c5229 (diff)
Fixed #19088 -- Always escape % inside blocktrans tag
Thanks vlinhart for the report and Ɓukasz Rekucki for the patch.
Diffstat (limited to 'django')
-rw-r--r--django/templatetags/i18n.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py
index 30eb6b5f76..5576beb4a3 100644
--- a/django/templatetags/i18n.py
+++ b/django/templatetags/i18n.py
@@ -110,13 +110,13 @@ class BlockTranslateNode(Node):
vars = []
for token in tokens:
if token.token_type == TOKEN_TEXT:
- result.append(token.contents)
+ result.append(token.contents.replace('%', '%%'))
elif token.token_type == TOKEN_VAR:
result.append('%%(%s)s' % token.contents)
vars.append(token.contents)
return ''.join(result), vars
- def render(self, context):
+ def render(self, context, nested=False):
if self.message_context:
message_context = self.message_context.resolve(context)
else:
@@ -128,13 +128,10 @@ class BlockTranslateNode(Node):
# the end of function
context.update(tmp_context)
singular, vars = self.render_token_list(self.singular)
- # Escape all isolated '%'
- singular = re.sub('%(?!\()', '%%', singular)
if self.plural and self.countervar and self.counter:
count = self.counter.resolve(context)
context[self.countervar] = count
plural, plural_vars = self.render_token_list(self.plural)
- plural = re.sub('%(?!\()', '%%', plural)
if message_context:
result = translation.npgettext(message_context, singular,
plural, count)
@@ -151,8 +148,12 @@ class BlockTranslateNode(Node):
try:
result = result % data
except (KeyError, ValueError):
+ if nested:
+ # Either string is malformed, or it's a bug
+ raise TemplateSyntaxError("'blocktrans' is unable to format "
+ "string returned by gettext: %r using %r" % (result, data))
with translation.override(None):
- result = self.render(context)
+ result = self.render(context, nested=True)
return result