mirror of https://github.com/django/django.git
Refs #34691 -- Optimized system check for unmatched angle brackets in path().
Follow up to d1855c4847
.
This commit is contained in:
parent
7f2bc365b3
commit
e5e9699e0f
|
@ -336,30 +336,21 @@ class RoutePattern(CheckURLMixin):
|
||||||
|
|
||||||
def _check_pattern_unmatched_angle_brackets(self):
|
def _check_pattern_unmatched_angle_brackets(self):
|
||||||
warnings = []
|
warnings = []
|
||||||
segments = self._route.split("/")
|
msg = "Your URL pattern %s has an unmatched '%s' bracket."
|
||||||
for segment in segments:
|
brackets = re.findall(r"[<>]", str(self._route))
|
||||||
open_bracket_counter = 0
|
open_bracket_counter = 0
|
||||||
unmatched_angle_bracket = None
|
for bracket in brackets:
|
||||||
for char in segment:
|
if bracket == "<":
|
||||||
if char == "<":
|
open_bracket_counter += 1
|
||||||
open_bracket_counter += 1
|
elif bracket == ">":
|
||||||
elif char == ">":
|
open_bracket_counter -= 1
|
||||||
open_bracket_counter -= 1
|
if open_bracket_counter < 0:
|
||||||
if open_bracket_counter < 0:
|
warnings.append(
|
||||||
unmatched_angle_bracket = ">"
|
Warning(msg % (self.describe(), ">"), id="urls.W010")
|
||||||
break
|
|
||||||
else:
|
|
||||||
if open_bracket_counter > 0:
|
|
||||||
unmatched_angle_bracket = "<"
|
|
||||||
|
|
||||||
if unmatched_angle_bracket is not None:
|
|
||||||
warnings.append(
|
|
||||||
Warning(
|
|
||||||
"Your URL pattern %s has an unmatched '%s' bracket."
|
|
||||||
% (self.describe(), unmatched_angle_bracket),
|
|
||||||
id="urls.W010",
|
|
||||||
)
|
)
|
||||||
)
|
open_bracket_counter = 0
|
||||||
|
if open_bracket_counter > 0:
|
||||||
|
warnings.append(Warning(msg % (self.describe(), "<"), id="urls.W010"))
|
||||||
return warnings
|
return warnings
|
||||||
|
|
||||||
def _compile(self, route):
|
def _compile(self, route):
|
||||||
|
|
Loading…
Reference in New Issue