summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaas van Schelven <klaas@vanschelven.com>2024-11-08 09:55:28 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-11-28 15:53:31 +0100
commit1722f2db5808708de6fc6e0f48af2d518be1e348 (patch)
tree70166b23c8639886907d251a3575ba78bc9bff9c
parent1636912bf1bacc1da65011c2b26ff48b2c9fad43 (diff)
Fixed #35897 -- Removed unnecessary escaping in template's get_exception_info().
-rw-r--r--django/template/base.py10
-rw-r--r--tests/template_tests/templates/test_extends_block_error.html2
-rw-r--r--tests/template_tests/tests.py25
3 files changed, 29 insertions, 8 deletions
diff --git a/django/template/base.py b/django/template/base.py
index b974495c9c..eaca428b10 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -57,7 +57,7 @@ from enum import Enum
from django.template.context import BaseContext
from django.utils.formats import localize
-from django.utils.html import conditional_escape, escape
+from django.utils.html import conditional_escape
from django.utils.regex_helper import _lazy_re_compile
from django.utils.safestring import SafeData, SafeString, mark_safe
from django.utils.text import get_text_list, smart_split, unescape_string_literal
@@ -247,10 +247,10 @@ class Template:
for num, next in enumerate(linebreak_iter(self.source)):
if start >= upto and end <= next:
line = num
- before = escape(self.source[upto:start])
- during = escape(self.source[start:end])
- after = escape(self.source[end:next])
- source_lines.append((num, escape(self.source[upto:next])))
+ before = self.source[upto:start]
+ during = self.source[start:end]
+ after = self.source[end:next]
+ source_lines.append((num, self.source[upto:next]))
upto = next
total = len(source_lines)
diff --git a/tests/template_tests/templates/test_extends_block_error.html b/tests/template_tests/templates/test_extends_block_error.html
index c4733747a2..8133c93ccd 100644
--- a/tests/template_tests/templates/test_extends_block_error.html
+++ b/tests/template_tests/templates/test_extends_block_error.html
@@ -1,2 +1,2 @@
{% extends "test_extends_block_error_parent.html" %}
-{% block content %}{% include "missing.html" %}{% endblock %}
+{% block content %}{% include "index.html" %}{% include "missing.html" %}{% include "index.html" %}{% endblock %}
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index 14df81669b..7364c7ca64 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -5,7 +5,6 @@ from django.template.base import UNKNOWN_SOURCE
from django.test import SimpleTestCase, override_settings
from django.urls import NoReverseMatch
from django.utils import translation
-from django.utils.html import escape
class TemplateTestMixin:
@@ -158,9 +157,31 @@ class TemplateTestMixin:
template.render(context)
if self.debug_engine:
self.assertEqual(
+ cm.exception.template_debug["before"],
+ '{% block content %}{% include "index.html" %}',
+ )
+ self.assertEqual(
cm.exception.template_debug["during"],
- escape('{% include "missing.html" %}'),
+ '{% include "missing.html" %}',
+ )
+ self.assertEqual(
+ cm.exception.template_debug["after"],
+ '{% include "index.html" %}{% endblock %}\n',
+ )
+ self.assertEqual(
+ cm.exception.template_debug["source_lines"][0],
+ (1, '{% extends "test_extends_block_error_parent.html" %}\n'),
+ )
+ self.assertEqual(
+ cm.exception.template_debug["source_lines"][1],
+ (
+ 2,
+ '{% block content %}{% include "index.html" %}'
+ '{% include "missing.html" %}'
+ '{% include "index.html" %}{% endblock %}\n',
+ ),
)
+ self.assertEqual(cm.exception.template_debug["source_lines"][2], (3, ""))
def test_super_errors(self):
"""