Skip to content

Commit 9e58198

Browse files
committed
fix(apigw): add all safe URI chars RFC3986
1 parent 625fc51 commit 9e58198

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
logger = logging.getLogger(__name__)
2222

2323
_DYNAMIC_ROUTE_PATTERN = r"(<\w+>)"
24-
_NAMED_GROUP_BOUNDARY_PATTERN = r"(?P\1[-%@.:\\w]+)"
24+
# Safe URI chars https://www.ietf.org/rfc/rfc3986.txt
25+
_NAMED_GROUP_BOUNDARY_PATTERN = r"(?P\1[-._~()'!*:@,;\\w]+)"
2526

2627

2728
class ProxyEventType(Enum):

tests/functional/event_handler/test_api_gateway.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,20 @@ def get_network_account(account_id: str, network_id: str):
703703
app.resolve(event, {})
704704

705705

706-
def test_non_word_chars_route():
706+
@pytest.mark.parametrize("req", [123456789, "[email protected]", "<foo>", "-._~'!*:@,;"])
707+
def test_non_word_chars_route(req):
707708
# GIVEN
708709
app = ApiGatewayResolver()
709710
event = deepcopy(LOAD_GW_EVENT)
710711

711712
# WHEN
712713
@app.get("/accounts/<account_id>")
713714
def get_account(account_id: str):
714-
assert account_id == "12345"
715+
assert account_id == f"{req}"
715716

716717
# THEN
717718
event["resource"] = "/accounts/{account_id}"
718-
event["path"] = "/accounts/12345"
719-
app.resolve(event, None)
719+
event["path"] = f"/accounts/{req}"
720+
721+
ret = app.resolve(event, None)
722+
assert ret["statusCode"] == 200

0 commit comments

Comments
 (0)