summaryrefslogtreecommitdiff
path: root/django/urls
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-11 22:45:31 +0200
committerGitHub <noreply@github.com>2023-07-11 22:45:31 +0200
commite5e9699e0fe1e7affe3c68082ed1e205726a4c79 (patch)
tree5ac64b7da4e4037b4dc1731684d723d2e996cdc5 /django/urls
parent7f2bc365b3652eaa8a8c19e58ddd35f062c68dbc (diff)
Refs #34691 -- Optimized system check for unmatched angle brackets in path().
Follow up to d1855c4847215f3afe3708736be13388bb6437eb.
Diffstat (limited to 'django/urls')
-rw-r--r--django/urls/resolvers.py37
1 files changed, 14 insertions, 23 deletions
diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py
index 432bf50076..89ae18694c 100644
--- a/django/urls/resolvers.py
+++ b/django/urls/resolvers.py
@@ -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):