mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
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):
|
||||
warnings = []
|
||||
segments = self._route.split("/")
|
||||
for segment in segments:
|
||||
open_bracket_counter = 0
|
||||
unmatched_angle_bracket = None
|
||||
for char in segment:
|
||||
if char == "<":
|
||||
open_bracket_counter += 1
|
||||
elif char == ">":
|
||||
open_bracket_counter -= 1
|
||||
if open_bracket_counter < 0:
|
||||
unmatched_angle_bracket = ">"
|
||||
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",
|
||||
msg = "Your URL pattern %s has an unmatched '%s' bracket."
|
||||
brackets = re.findall(r"[<>]", str(self._route))
|
||||
open_bracket_counter = 0
|
||||
for bracket in brackets:
|
||||
if bracket == "<":
|
||||
open_bracket_counter += 1
|
||||
elif bracket == ">":
|
||||
open_bracket_counter -= 1
|
||||
if open_bracket_counter < 0:
|
||||
warnings.append(
|
||||
Warning(msg % (self.describe(), ">"), id="urls.W010")
|
||||
)
|
||||
)
|
||||
open_bracket_counter = 0
|
||||
if open_bracket_counter > 0:
|
||||
warnings.append(Warning(msg % (self.describe(), "<"), id="urls.W010"))
|
||||
return warnings
|
||||
|
||||
def _compile(self, route):
|
||||
|
Loading…
Reference in New Issue
Block a user