Skip to content

Commit e9530c8

Browse files
committed
fix(parameters): allow whitespace in routes' path parmeter
1 parent 8c4eca0 commit e9530c8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
_DYNAMIC_ROUTE_PATTERN = r"(<\w+>)"
2727
_SAFE_URI = "-._~()'!*:@,;" # https://www.ietf.org/rfc/rfc3986.txt
2828
# API GW/ALB decode non-safe URI chars; we must support them too
29-
_UNSAFE_URI = "%<>\[\]{}|^" # noqa: W605
29+
_UNSAFE_URI = "%<> \[\]{}|^" # noqa: W605
3030
_NAMED_GROUP_BOUNDARY_PATTERN = fr"(?P\1[{_SAFE_URI}{_UNSAFE_URI}\\w]+)"
3131

3232

tests/functional/event_handler/test_api_gateway.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,12 @@ def test_similar_dynamic_routes():
688688
# r'^/accounts/(?P<account_id>\\w+\\b)$' # noqa: E800
689689
@app.get("/accounts/<account_id>")
690690
def get_account(account_id: str):
691-
assert account_id == "single_account"
691+
assert account_id in ("single_account", "single account")
692692

693693
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$' # noqa: E800
694694
@app.get("/accounts/<account_id>/source_networks")
695695
def get_account_networks(account_id: str):
696-
assert account_id == "nested_account"
696+
assert account_id in ("nested_account", "nested account")
697697

698698
# r'^/accounts/(?P<account_id>\\w+\\b)/source_networks/(?P<network_id>\\w+\\b)$' # noqa: E800
699699
@app.get("/accounts/<account_id>/source_networks/<network_id>")
@@ -706,10 +706,18 @@ def get_network_account(account_id: str, network_id: str):
706706
event["path"] = "/accounts/single_account"
707707
app.resolve(event, None)
708708

709+
event["resource"] = "/accounts/{account_id}"
710+
event["path"] = "/accounts/single account"
711+
app.resolve(event, None)
712+
709713
event["resource"] = "/accounts/{account_id}/source_networks"
710714
event["path"] = "/accounts/nested_account/source_networks"
711715
app.resolve(event, None)
712716

717+
event["resource"] = "/accounts/{account_id}/source_networks"
718+
event["path"] = "/accounts/nested account/source_networks"
719+
app.resolve(event, None)
720+
713721
event["resource"] = "/accounts/{account_id}/source_networks/{network_id}"
714722
event["path"] = "/accounts/nested_account/source_networks/network"
715723
app.resolve(event, {})

0 commit comments

Comments
 (0)