Skip to content

Commit

Permalink
Fix handling of trailing slash to match API Gateway
Browse files Browse the repository at this point in the history
API Gateway will not match a URI against a route that has a capture
group as the last path component if that capture group would be filled
with an empty string. Example:

With the route:
/resource/{name}

/resource/bob matches
/resource/    does not match

Previously local mode would match both URIs to that route, setting the
name parameter to an empty string.

closes aws#582
  • Loading branch information
stealthycoin committed Oct 31, 2017
1 parent abad35f commit 2f375f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def match_route(self, url):
url_parts = route_url.split('/')
if len(parts) == len(url_parts):
for i, j in zip(parts, url_parts):
if j.startswith('{') and j.endswith('}'):
if j.startswith('{') and j.endswith('}') and i != '':
captured[j[1:-1]] = i
continue
if i != j:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def test_can_deny_unauthed_request(auth_handler):
('/foo/other', '/foo/{capture}'),
('/names/foo', '/names/{capture}'),
('/names/bar', '/names/{capture}'),
('/names/', None),
('/nomatch', None),
('/names/bar/wrong', None),
('/a/z/c', '/a/{capture}/c'),
Expand Down

0 comments on commit 2f375f4

Please sign in to comment.