From fc2bd40fc76996306efc1f8de581708d8c5a2943 Mon Sep 17 00:00:00 2001 From: Greg Twohig Date: Fri, 6 Aug 2021 13:45:17 +0300 Subject: [PATCH] Fixed #32990 -- Simplified and optimized tag regex. Thanks Chris Jerdonek for the review. --- AUTHORS | 1 + django/template/base.py | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2d9d23f73e..3e4aa1aa2c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -356,6 +356,7 @@ answer newbie questions, and generally made Django that much better: Graham Carlyle Grant Jenks Greg Chapple + Greg Twohig Gregor Allensworth Gregor Müllegger Grigory Fateyev diff --git a/django/template/base.py b/django/template/base.py index a8c2e5774e..c01f36a34e 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -85,12 +85,10 @@ SINGLE_BRACE_END = '}' # (e.g. strings) UNKNOWN_SOURCE = '' -# match a variable or block tag and capture the entire tag, including start/end -# delimiters -tag_re = (_lazy_re_compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % - (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), - re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), - re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END)))) +# Match BLOCK_TAG_*, VARIABLE_TAG_*, and COMMENT_TAG_* tags and capture the +# entire tag, including start/end delimiters. Using re.compile() is faster +# than instantiating SimpleLazyObject with _lazy_re_compile(). +tag_re = re.compile(r'({%.*?%}|{{.*?}}|{#.*?#})') logger = logging.getLogger('django.template')