Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_DYNAMIC_ROUTE_PATTERN = r"(<\w+>)"
_SAFE_URI = "-._~()'!*:@,;" # https://www.ietf.org/rfc/rfc3986.txt
# API GW/ALB decode non-safe URI chars; we must support them too
_UNSAFE_URI = "%<>\[\]{}|^" # noqa: W605
_UNSAFE_URI = "%<> \[\]{}|^" # noqa: W605
_NAMED_GROUP_BOUNDARY_PATTERN = fr"(?P\1[{_SAFE_URI}{_UNSAFE_URI}\\w]+)"


Expand Down
36 changes: 36 additions & 0 deletions tests/functional/event_handler/test_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,42 @@ def get_network_account(account_id: str, network_id: str):
app.resolve(event, {})


def test_similar_dynamic_routes_with_whitespaces():
# GIVEN
app = ApiGatewayResolver()
event = deepcopy(LOAD_GW_EVENT)

# WHEN
# r'^/accounts/(?P<account_id>\\w+\\b)$' # noqa: E800
@app.get("/accounts/<account_id>")
def get_account(account_id: str):
assert account_id == "single account"

# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$' # noqa: E800
@app.get("/accounts/<account_id>/source_networks")
def get_account_networks(account_id: str):
assert account_id == "nested account"

# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks/(?P<network_id>\\w+\\b)$' # noqa: E800
@app.get("/accounts/<account_id>/source_networks/<network_id>")
def get_network_account(account_id: str, network_id: str):
assert account_id == "nested account"
assert network_id == "network 123"

# THEN
event["resource"] = "/accounts/{account_id}"
event["path"] = "/accounts/single account"
app.resolve(event, None)

event["resource"] = "/accounts/{account_id}/source_networks"
event["path"] = "/accounts/nested account/source_networks"
app.resolve(event, None)

event["resource"] = "/accounts/{account_id}/source_networks/{network_id}"
event["path"] = "/accounts/nested account/source_networks/network 123"
app.resolve(event, {})


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