Opened 9 years ago

Closed 9 years ago

#764 closed defect (fixed)

[i18n] blocktrans parsing error when filter argument contains spaces

Reported by: Nebojša Đorđević - nesh <nesh@…> Owned by: hugo
Component: Template system Version:
Severity: normal Keywords:
Cc: nesh@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When I using this:

{% blocktrans with object.pub_date|date:"F j, Y" as date %}
Posted by <strong>{{ object.author }}</strong> on {{ date }}
{% endblocktrans %}

I'm getting following exception

...
  File "/store/django/django/core/template/__init__.py", line 221, in parse
    nodelist.append(registered_tags[command](self, token))

  File "/store/django/django/templatetags/i18n.py", line 189, in do_block_translate
    (countervar, counter, extra_context) = BlockTranslateParser(token.contents).top()

  File "/store/django/django/templatetags/i18n.py", line 178, in top
    raise TemplateSyntaxError, "variable bindings in 'blocktrans' must be 'with value as variable'"

TemplateSyntaxError: variable bindings in 'blocktrans' must be 'with value as variable'

Change History (4)

comment:1 Changed 9 years ago by Nebojša Đorđević - nesh <nesh@…>

  • Component changed from Admin interface to Template system

comment:2 Changed 9 years ago by hugo

  • Owner changed from adrian to hugo

comment:3 Changed 9 years ago by hugo

  • Status changed from new to assigned

This is a problem of the still-not-perfect parser for parameters in the blocktrans tag. It doesn't currently handle any filter expressions that contain blanks. Actually that's a common problem, if you use the split-on-whitespace approach to "preparse" the tag arguments, you end up with this problem, as it breaks on blanks in filter expressions. I think this can be fixed by making the tag parser a bit more intelligent to correctly handle filter expressions with parameters. Will have a look at that at the weekend.

comment:4 Changed 9 years ago by hugo

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [1207]) fixes #764 - the TokenParser now respects string parameters to filters that contain blanks.

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