Skip to content

Commit

Permalink
Bugfix ensure that the entire part is matched
Browse files Browse the repository at this point in the history
Previously the router would accept a partial match of a part, which is
contrary to how the router is meant to work. For example if the rule
to be matched was `d+` the router would match `2dfd` as `2` and
silently forget the rest.
  • Loading branch information
pgjones committed Jul 26, 2022
1 parent 76ccf1f commit 9afd9a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/werkzeug/routing/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def _parse_rule(self, rule: str) -> t.Iterable[RulePart]:
-len(argument_weights),
argument_weights,
)
if final:
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 9afd9a2

Please sign in to comment.