diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-11-28 21:04:05 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-11-28 21:04:05 +0000 |
| commit | 9130765ff9823055654207149c051eb2fe7c7165 (patch) | |
| tree | 2290c977472088093815d451ac88dd16d3aac76c | |
| parent | 5a5a71edcdbb2062dd5480ebb05e8098dc49d3cc (diff) | |
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
| -rw-r--r-- | django/template/__init__.py | 4 | ||||
| -rw-r--r-- | 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"), |
