Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#6048 closed (worksforme)

compile_filter() does not allow quote escaping for constant strings

Reported by: miracle2k Owned by: nobody
Component: Template system Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


{{ "abc \" def" }}
{% mytag with value="abc \" def" %}

In both cases, Parser.compile_filter().resolve() will return the string as

abc \" def

Actually, FilterExpression.init() in django.template, which does the parsing, calls

constant_arg.replace(r'\"', '"'))

when resolving the filter part of the expression - but not for the variable part.

A workaround is:

0|default:"abc \" def"

Change History (2)

comment:1 Changed 8 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

Seems to work for me...

>>> from django.template import *
>>> c = Context()
>>> t = Template(r'{{ "test \" me" }}')
>>> t.render(c)
u'test " me'

Want to make up some tests which show your problem and reopen?

comment:2 Changed 8 years ago by mtredinnick

I'm fairly sure that the difference between the original reporter's observation and Chris' is because the latter's checkout is more up to date. This was only fixed in [6724] (a few hours ago).

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