Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "local",
"description": "Fix path parameters from a non matching route leaking into the matched route in local mode."
}
2 changes: 1 addition & 1 deletion chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def match_route(self, url: str) -> MatchResult:
if path != '/' and path.endswith('/'):
path = path[:-1]
parts = path.split('/')
captured = {}
for route_url in self.route_urls:
url_parts = route_url.split('/')
if len(parts) == len(url_parts):
captured = {}
for i, j in zip(parts, url_parts):
if j.startswith('{') and j.endswith('}'):
captured[j[1:-1]] = i
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ def test_can_match_exact_route(actual_url, matched_url):
matcher.match_route(actual_url)


def test_does_not_capture_params_from_unmatched_routes():
matcher = local.RouteMatcher(['/{x}/c', '/{y}/d'])
assert matcher.match_route('/foo/d').captured == {'y': 'foo'}


def test_lambda_event_contains_source_ip():
converter = local.LambdaEventConverter(
local.RouteMatcher(['/foo/bar']))
Expand Down