Skip to content

Commit

Permalink
Merge pull request #2470 from pgjones/2.2.x
Browse files Browse the repository at this point in the history
Bugfix ensure that the entire part is matched
  • Loading branch information
davidism authored Jul 26, 2022
2 parents 76ccf1f + b59eb67 commit 5c85706
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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")},
)

0 comments on commit 5c85706

Please sign in to comment.