diff --git a/CHANGES.rst b/CHANGES.rst index 662bf0ccd..70d7b9715 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,8 @@ Unreleased - Fix router so that ``/path/`` will match a rule ``/path`` if strict slashes mode is disabled for the rule. :issue:`2467` +- Fix router so that partial part matches are not allowed + i.e. ``/2df`` does not match ``/``. :pr:`2470` - Restore ``ValidationError`` to be importable from ``werkzeug.routing``. :issue:`2465` diff --git a/src/werkzeug/routing/rules.py b/src/werkzeug/routing/rules.py index f16e5668a..29c785688 100644 --- a/src/werkzeug/routing/rules.py +++ b/src/werkzeug/routing/rules.py @@ -625,8 +625,8 @@ def _parse_rule(self, rule: str) -> t.Iterable[RulePart]: -len(argument_weights), argument_weights, ) - if final: - content += r"$\Z" + if not static: + content += r"\Z" yield RulePart( content=content, final=final, static=static, weight=weight ) diff --git a/tests/test_routing.py b/tests/test_routing.py index 0c28a1867..4f9fc2cc3 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -1400,3 +1400,18 @@ def test_newline_match(): with pytest.raises(NotFound): a.match("/hello\n") + + +def test_weighting(): + m = r.Map( + [ + r.Rule("/", endpoint="int"), + r.Rule("/", endpoint="uuid"), + ] + ) + a = m.bind("localhost") + + assert a.match("/2b5b0911-fdcf-4dd2-921b-28ace88db8a0") == ( + "uuid", + {"value": uuid.UUID("2b5b0911-fdcf-4dd2-921b-28ace88db8a0")}, + )