Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix ensure that the entire part is matched #2470

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``/<int>``. :pr:`2470`
- Restore ``ValidationError`` to be importable from
``werkzeug.routing``. :issue:`2465`

Expand Down
4 changes: 2 additions & 2 deletions src/werkzeug/routing/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,3 +1400,18 @@ def test_newline_match():

with pytest.raises(NotFound):
a.match("/hello\n")


def test_weighting():
m = r.Map(
[
r.Rule("/<int:value>", endpoint="int"),
r.Rule("/<uuid:value>", endpoint="uuid"),
]
)
a = m.bind("localhost")

assert a.match("/2b5b0911-fdcf-4dd2-921b-28ace88db8a0") == (
"uuid",
{"value": uuid.UUID("2b5b0911-fdcf-4dd2-921b-28ace88db8a0")},
)