From b5388a3a80cafcce2e34196d8e81cf5b48eb33bb Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 8 Aug 2026 22:28:34 +0100 Subject: [PATCH] Fixed #37257, Refs #35738 -- Prevented double-dot deprecation warnings for template literals. The deprecation warning for double-dot variable lookups checked str(filter_expression.var), which for constants is the resolved literal value rather than a variable lookup. Templates containing string or translated string literals with two consecutive dots, such as {{ "a..b" }} or {{ 'a..b'|upper }}, therefore incorrectly raised a RemovedInDjango70Warning. The check now only applies when the filter expression's variable is a Variable lookup. Regression in 5d911f2d2fecc703be91b2b9b28acc59d34b35f3. --- django/template/base.py | 2 +- docs/releases/6.1.1.txt | 4 +++- tests/template_tests/syntax_tests/test_basic.py | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/django/template/base.py b/django/template/base.py index d180b6816514..2f4d447590bd 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -556,7 +556,7 @@ def parse(self, parse_until=None): except TemplateSyntaxError as e: raise self.error(token, e) var_node = VariableNode(filter_expression) - if ".." in str(filter_expression.var): + if filter_expression.is_var and ".." in filter_expression.var.var: warnings.warn( "Support for double-dot lookups '..' which maps to a " "lookup of the empty string is deprecated.\n" diff --git a/docs/releases/6.1.1.txt b/docs/releases/6.1.1.txt index 9f2fe9a0e77c..ec7b8d80899e 100644 --- a/docs/releases/6.1.1.txt +++ b/docs/releases/6.1.1.txt @@ -9,4 +9,6 @@ Django 6.1.1 fixes several bugs in 6.1. Bugfixes ======== -* ... +* Fixed a regression in Django 6.1 where the deprecation of double-dot variable + lookups incorrectly applied to string and translated template literals + containing two consecutive dots, such as ``{{ "a..b" }}`` (:ticket:`37257`). diff --git a/tests/template_tests/syntax_tests/test_basic.py b/tests/template_tests/syntax_tests/test_basic.py index 47bc949fdcd8..fe43e907f330 100644 --- a/tests/template_tests/syntax_tests/test_basic.py +++ b/tests/template_tests/syntax_tests/test_basic.py @@ -431,6 +431,20 @@ def test_double_dot_lookup(self): # ): # self.engine.render_to_string("template") + def test_double_dot_in_literal(self): + tests = [ + ('{{ "hello..world" }}', "hello..world"), + ("{{ 'a..b'|upper }}", "A..B"), + ('{{ missing|default:"a..b" }}', "a..b"), + ('{{ _("a..b") }}', "a..b"), + ] + engine = Engine() + for template_string, expected in tests: + with self.subTest(template_string=template_string): + template = engine.from_string(template_string) + output = template.render(Context({})) + self.assertEqual(output, expected) + class BlockContextTests(SimpleTestCase): def test_repr(self):