File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
scaleway_functions_python/local Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,6 @@ def format_http_event(request: "Request") -> "Event":
4141 try :
4242 b64decode (body , validate = True ).decode ("utf-8" )
4343 event ["isBase64Encoded" ] = True
44- except (binascii .Error , UnicodeDecodeError ):
44+ except (binascii .Error , UnicodeDecodeError , ValueError ):
4545 pass
4646 return event
Original file line number Diff line number Diff line change 11import pytest
2- from flask import Flask , request
2+ from flask import Flask , Request , request
3+ from werkzeug .test import EnvironBuilder
34
45from scaleway_functions_python .local .event import format_http_event
56
@@ -48,3 +49,16 @@ def test_format_http_event(app):
4849 assert event ["requestContext" ] == expected_request_context
4950
5051 assert event ["body" ] == ""
52+
53+ def test_format_http_event_with_non_unicode_body ():
54+ # Create a request with non-unicode body
55+ non_unicode_body = b'\xff \xfe \xfd ' # Invalid UTF-8 sequence
56+ builder = EnvironBuilder (method = 'POST' , data = non_unicode_body )
57+ r = Request (builder .get_environ ())
58+
59+ # Call the function and check the result
60+ event = format_http_event (r )
61+
62+ assert event is not None
63+ assert 'body' in event
64+ assert event .get ('isBase64Encoded' , False ) is False
You can’t perform that action at this time.
0 commit comments