From bd4402b7f5e5acf0c1c0d1664e109688f484d5ca Mon Sep 17 00:00:00 2001 From: Steffen Leistner Date: Thu, 5 Nov 2020 13:56:51 +0100 Subject: [PATCH] fix(HTTPHandler): do not parse body if value is None --- lambda_handlers/handlers/http_handler.py | 2 +- lambda_handlers/handlers/tests/test_http_handler.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lambda_handlers/handlers/http_handler.py b/lambda_handlers/handlers/http_handler.py index 27f20342..b2aee2b4 100644 --- a/lambda_handlers/handlers/http_handler.py +++ b/lambda_handlers/handlers/http_handler.py @@ -54,7 +54,7 @@ def on_exception(self, exception): def format_input(self, event): """Return `event` with a formatted `event['body']`.""" - if 'body' in event: + if 'body' in event and event['body']: try: event['body'] = self._input_format.format(event['body']) except FormatError as error: diff --git a/lambda_handlers/handlers/tests/test_http_handler.py b/lambda_handlers/handlers/tests/test_http_handler.py index c9e03c57..b3bf06a8 100644 --- a/lambda_handlers/handlers/tests/test_http_handler.py +++ b/lambda_handlers/handlers/tests/test_http_handler.py @@ -20,6 +20,11 @@ def test_empty_body_validation(self, handler): assert isinstance(response, dict) assert response['statusCode'] == 200 + def test_none_body_validation(self, handler): + response = handler({'body': None}, None) + assert isinstance(response, dict) + assert response['statusCode'] == 200 + def test_invalid_body_validation(self, handler): response = handler({'body': '{.x'}, None) assert isinstance(response, dict)