Skip to content

Commit 5684ef1

Browse files
committed
fix: added tests
1 parent e60d3b3 commit 5684ef1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,11 @@ def _remove_prefix(self, path: str) -> str:
724724
if isinstance(prefix, Pattern):
725725
path = re.sub(prefix, "", path)
726726

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

732733
return path
733734

tests/functional/event_handler/test_api_gateway.py

+12
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,18 @@ def foo():
10981098
assert response["statusCode"] == 200
10991099

11001100

1101+
def test_empty_path_when_using_regexes():
1102+
app = ApiGatewayResolver(strip_prefixes=[re.compile(r"/(dev|stg)")])
1103+
1104+
@app.get("/")
1105+
def foo():
1106+
...
1107+
1108+
response = app({"httpMethod": "GET", "path": "/dev"}, None)
1109+
1110+
assert response["statusCode"] == 200
1111+
1112+
11011113
@pytest.mark.parametrize(
11021114
"prefix",
11031115
[

0 commit comments

Comments
 (0)