Skip to content

Commit e21b97d

Browse files
author
Michael Brewer
committed
Merge branch 'develop' into chore-housekeeping
2 parents 02e70e4 + cf001a6 commit e21b97d

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) fo
77

88
## [Unreleased]
99

10+
## [1.18.1] - 2021-07-23
11+
12+
### Bug Fixes
13+
14+
* **api-gateway:** route regression for non-word and unsafe URI chars ([#556](https://github.com/awslabs/aws-lambda-powertools-python/issues/556))
15+
1016
## [1.18.0] - 2021-07-20
1117

1218
### Bug Fixes

aws_lambda_powertools/event_handler/api_gateway.py

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

2323
_DYNAMIC_ROUTE_PATTERN = r"(<\w+>)"
24-
_NAMED_GROUP_BOUNDARY_PATTERN = r"(?P\1\\w+\\b)"
24+
_SAFE_URI = "-._~()'!*:@,;" # https://www.ietf.org/rfc/rfc3986.txt
25+
# API GW/ALB decode non-safe URI chars; we must support them too
26+
_UNSAFE_URI = "%<>\[\]{}|^" # noqa: W605
27+
28+
_NAMED_GROUP_BOUNDARY_PATTERN = fr"(?P\1[{_SAFE_URI}{_UNSAFE_URI}\\w]+)"
2529

2630

2731
class ProxyEventType(Enum):

poetry.lock

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "aws_lambda_powertools"
3-
version = "1.18.0"
3+
version = "1.18.1"
44
description = "Python utilities for AWS Lambda functions including but not limited to tracing, logging and custom metric"
55
authors = ["Amazon Web Services"]
66
include = ["aws_lambda_powertools/py.typed"]
@@ -32,7 +32,7 @@ coverage = {extras = ["toml"], version = "^5.5"}
3232
pytest = "^6.2.2"
3333
black = "^20.8b1"
3434
flake8 = "^3.9.0"
35-
flake8-black = "^0.2.1"
35+
flake8-black = "^0.2.3"
3636
flake8-builtins = "^1.5.3"
3737
flake8-comprehensions = "^3.4.0"
3838
flake8-debugger = "^4.0.0"
@@ -49,7 +49,7 @@ radon = "^4.5.0"
4949
xenon = "^0.7.3"
5050
flake8-eradicate = "^1.1.0"
5151
flake8-bugbear = "^21.3.2"
52-
mkdocs-material = "^7.1.11"
52+
mkdocs-material = "^7.2.0"
5353
mkdocs-git-revision-date-plugin = "^0.3.1"
5454
mike = "^0.6.0"
5555
mypy = "^0.910"

tests/functional/event_handler/test_api_gateway.py

+27
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,30 @@ def get_network_account(account_id: str, network_id: str):
701701
event["resource"] = "/accounts/{account_id}/source_networks/{network_id}"
702702
event["path"] = "/accounts/nested_account/source_networks/network"
703703
app.resolve(event, {})
704+
705+
706+
@pytest.mark.parametrize(
707+
"req",
708+
[
709+
pytest.param(123456789, id="num"),
710+
pytest.param("[email protected]", id="email"),
711+
pytest.param("-._~'!*:@,;()", id="safe-rfc3986"),
712+
pytest.param("%<>[]{}|^", id="unsafe-rfc3986"),
713+
],
714+
)
715+
def test_non_word_chars_route(req):
716+
# GIVEN
717+
app = ApiGatewayResolver()
718+
event = deepcopy(LOAD_GW_EVENT)
719+
720+
# WHEN
721+
@app.get("/accounts/<account_id>")
722+
def get_account(account_id: str):
723+
assert account_id == f"{req}"
724+
725+
# THEN
726+
event["resource"] = "/accounts/{account_id}"
727+
event["path"] = f"/accounts/{req}"
728+
729+
ret = app.resolve(event, None)
730+
assert ret["statusCode"] == 200

0 commit comments

Comments
 (0)