Skip to content

Commit 5c85706

Browse files
authored
Merge pull request #2470 from pgjones/2.2.x
Bugfix ensure that the entire part is matched
2 parents 76ccf1f + b59eb67 commit 5c85706

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Unreleased
77

88
- Fix router so that ``/path/`` will match a rule ``/path`` if strict
99
slashes mode is disabled for the rule. :issue:`2467`
10+
- Fix router so that partial part matches are not allowed
11+
i.e. ``/2df`` does not match ``/<int>``. :pr:`2470`
1012
- Restore ``ValidationError`` to be importable from
1113
``werkzeug.routing``. :issue:`2465`
1214

src/werkzeug/routing/rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ def _parse_rule(self, rule: str) -> t.Iterable[RulePart]:
625625
-len(argument_weights),
626626
argument_weights,
627627
)
628-
if final:
629-
content += r"$\Z"
628+
if not static:
629+
content += r"\Z"
630630
yield RulePart(
631631
content=content, final=final, static=static, weight=weight
632632
)

tests/test_routing.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,3 +1400,18 @@ def test_newline_match():
14001400

14011401
with pytest.raises(NotFound):
14021402
a.match("/hello\n")
1403+
1404+
1405+
def test_weighting():
1406+
m = r.Map(
1407+
[
1408+
r.Rule("/<int:value>", endpoint="int"),
1409+
r.Rule("/<uuid:value>", endpoint="uuid"),
1410+
]
1411+
)
1412+
a = m.bind("localhost")
1413+
1414+
assert a.match("/2b5b0911-fdcf-4dd2-921b-28ace88db8a0") == (
1415+
"uuid",
1416+
{"value": uuid.UUID("2b5b0911-fdcf-4dd2-921b-28ace88db8a0")},
1417+
)

0 commit comments

Comments
 (0)