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):