Fixed #5890 -- fixed the far edge-case of allowing constant strings inside
template template markers: we now treat embedded, escaped double quotes consistently with constant string arguments to filters. Patch from Dmitri Fedortchenko. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6724 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5a5a71edcd
commit
9130765ff9
|
@ -547,9 +547,9 @@ class FilterExpression(object):
|
|||
if var == None:
|
||||
var, constant, i18n_constant = match.group("var", "constant", "i18n_constant")
|
||||
if i18n_constant:
|
||||
var = '"%s"' % _(i18n_constant)
|
||||
var = '"%s"' % _(i18n_constant.replace(r'\"', '"'))
|
||||
elif constant:
|
||||
var = '"%s"' % constant
|
||||
var = '"%s"' % constant.replace(r'\"', '"')
|
||||
upto = match.end()
|
||||
if var == None:
|
||||
raise TemplateSyntaxError, "Could not find variable at start of %s" % token
|
||||
|
|
|
@ -268,6 +268,12 @@ class Templates(unittest.TestCase):
|
|||
# Embedded newlines make it not-a-tag.
|
||||
'basic-syntax24': ("{{ moo\n }}", {}, "{{ moo\n }}"),
|
||||
|
||||
# Literal strings are permitted inside variables, mostly for i18n
|
||||
# purposes.
|
||||
'basic-syntax25': ('{{ "fred" }}', {}, "fred"),
|
||||
'basic-syntax26': (r'{{ "\"fred\"" }}', {}, "\"fred\""),
|
||||
'basic-syntax27': (r'{{ _("\"fred\"") }}', {}, "\"fred\""),
|
||||
|
||||
# List-index syntax allows a template to access a certain item of a subscriptable object.
|
||||
'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),
|
||||
|
||||
|
|
Loading…
Reference in New Issue