From 9130765ff9823055654207149c051eb2fe7c7165 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 28 Nov 2007 21:04:05 +0000 Subject: [PATCH] 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 --- django/template/__init__.py | 4 ++-- tests/regressiontests/templates/tests.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/django/template/__init__.py b/django/template/__init__.py index 761c08d6c9..c68a4b544d 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -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 diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 5c3a0a9081..f3c131dd91 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -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"),