Skip to content

Commit

Permalink
fix: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfonseca committed Aug 14, 2023
1 parent e60d3b3 commit 5684ef1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,11 @@ def _remove_prefix(self, path: str) -> str:
if isinstance(prefix, Pattern):
path = re.sub(prefix, "", path)

# When using regexes, we might get into a point where everything is removed
# from the string, so we check if it's empty and change it accordingly.
if not path:
path = "/"
# When using regexes, we might get into a point where everything is removed
# from the string, so we check if it's empty and return /, since there's nothing
# else to strip anymore.
if not path:
return "/"

return path

Expand Down
12 changes: 12 additions & 0 deletions tests/functional/event_handler/test_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,18 @@ def foo():
assert response["statusCode"] == 200


def test_empty_path_when_using_regexes():
app = ApiGatewayResolver(strip_prefixes=[re.compile(r"/(dev|stg)")])

@app.get("/")
def foo():
...

response = app({"httpMethod": "GET", "path": "/dev"}, None)

assert response["statusCode"] == 200


@pytest.mark.parametrize(
"prefix",
[
Expand Down

0 comments on commit 5684ef1

Please sign in to comment.