Opened 17 years ago

Closed 14 years ago

Last modified 11 years ago

#4982 closed Uncategorized (fixed)

{% blocktrans %} does not escape % in text

Reported by: nostgard <nostgard@…> Owned by: Tomáš Kopeček
Component: Internationalization Version: dev
Severity: Normal Keywords: sprintsept14
Cc: permonik@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

When you try to use a blocktrans with a percent sign in it. When the percent is escaped (%%) it renders fine. It does not occur when using a trans tag.

>>> from django.template import Context, Template
>>> t1 = Template('{% load i18n %}{% blocktrans %}We lost 5% today.{% endblocktrans %}')
>>> t2 = Template('{% load i18n %}{% blocktrans %}We lost 5%% today.{% endblocktrans %}')
>>> t3 = Template('{% load i18n %}{% trans "We lost 5% today." %}')
>>> c = Context()
>>> t1.render(c)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "D:\Python\lib\site-packages\django\template\__init__.py", line 181, in render
    return self.nodelist.render(context)
  File "D:\Python\lib\site-packages\django\template\__init__.py", line 736, in render
    bits.append(self.render_node(node, context))
  File "D:\Python\lib\site-packages\django\template\__init__.py", line 764, in render_node
    raise wrapped
TemplateSyntaxError: Caught an exception while rendering: unsupported format character 't' (0x74) at index 11

Original Traceback (most recent call last):
  File "D:\Python\lib\site-packages\django\template\__init__.py", line 754, in render_node
    result = node.render(context)
  File "D:\Python\lib\site-packages\django\templatetags\i18n.py", line 73, in render
    result = translation.ugettext(singular) % context
ValueError: unsupported format character 't' (0x74) at index 11

>>> t2.render(c)
u'We lost 5% today.'
>>> t3.render(c)
u'We lost 5% today.'

Attachments (1)

patch.diff (1016 bytes ) - added by permonik@… 17 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedAccepted

comment:2 by John Shaffer <jshaffer2112@…>, 17 years ago

Component: TranslationsInternationalization

by permonik@…, 17 years ago

Attachment: patch.diff added

comment:3 by permonik@…, 17 years ago

Has patch: set

Blocktrans creates template string with %()s, but doesn't correctly escape % signs in original text. Patch attached, make-messages.py works as intended - so no other harm in i18n machinery.

comment:4 by anonymous, 17 years ago

Cc: permonik@… added

comment:5 by Tomáš Kopeček, 17 years ago

Owner: changed from nobody to Tomáš Kopeček
Status: newassigned

comment:6 by Tomáš Kopeček, 17 years ago

Keywords: sprintsept14 added

comment:7 by Tomáš Kopeček, 17 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: assignedclosed

(In [6565]) Fixed #4982 -- Fixed handling of '%' symbols in 'blocktrans' blocks. Thanks,
permonik@….

comment:9 by nasmon, 15 years ago

Patch needs improvement: set
Resolution: fixed
Status: closedreopened

On Django 1.2.1:
When using single % inside blocktrans, "django-admin.py makemessages" won't work and as %% inside the template, the output still is %%, due to the patch above. When removing the patch line, everything works ok.

in reply to:  9 comment:10 by Tomáš Kopeček, 14 years ago

Cc: permonik@… added; permonik@… removed

Replying to nasmon:

On Django 1.2.1:
When using single % inside blocktrans, "django-admin.py makemessages" won't work and as %% inside the template, the output still is %%, due to the patch above. When removing the patch line, everything works ok.

Can you attach some working example? For me is everything working ok with 1.2.1 tree.

comment:11 by Malcolm Tredinnick, 14 years ago

Resolution: fixed
Status: reopenedclosed
Triage Stage: Ready for checkinAccepted

I can't repeat this problem, either. Closing for now. Please open a new ticket if there's a specific failure case, because we're not going to revert this change -- at the time it was applied, it fixed a concrete problem -- so it's a matter of tweaking the current code to fix things if there's a concrete failure case.

Reclosing as "fixed" to restore previous state.

comment:12 by Claude Paroz, 13 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

FYI, I've reopened the issue with patch/test case in #16721.

comment:13 by Shailen Sobhee, 11 years ago

The bug is still present in Django 1.5.2

Note: See TracTickets for help on using tickets.
Back to Top