From 10af0b6a577dd0007d34a90620469f001040e49d Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Fri, 8 Nov 2024 09:55:28 +0100 Subject: [PATCH] Fixed #35897 -- Removed unnecessary escaping in template's get_exception_info(). --- django/template/base.py | 10 +++---- .../templates/test_extends_block_error.html | 2 +- tests/template_tests/tests.py | 27 ++++++++++++++++--- 3 files changed, 30 insertions(+), 9 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["during"], - escape('{% include "missing.html" %}'), + cm.exception.template_debug["before"], + '{% block content %}{% include "index.html" %}', ) + self.assertEqual( + cm.exception.template_debug["during"], + '{% 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): """