From 2a55afeed7e769877d9f6f1eb7aab7ff595e1313 Mon Sep 17 00:00:00 2001 From: James Ward Date: Fri, 27 Dec 2024 11:30:50 -0500 Subject: [PATCH] fix: include carriage return in multipartform.decode() (#10270) --- CHANGES/10270.bugfix.rst | 2 ++ CONTRIBUTORS.txt | 1 + aiohttp/multipart.py | 2 +- tests/test_web_response.py | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 CHANGES/10270.bugfix.rst diff --git a/CHANGES/10270.bugfix.rst b/CHANGES/10270.bugfix.rst new file mode 100644 index 00000000000..e3252464dc8 --- /dev/null +++ b/CHANGES/10270.bugfix.rst @@ -0,0 +1,2 @@ +``MultipartForm.decode()`` must follow RFC1341 7.2.1 with a ``CRLF`` after the boundary +-- by :user:`imnotjames`. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 591142d469e..03e35ce789f 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -175,6 +175,7 @@ Jaesung Lee Jake Davis Jakob Ackermann Jakub Wilk +James Ward Jan Buchar Jan Gosmann Jarno Elonen diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index dc25a83b17a..052e420a302 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -983,7 +983,7 @@ def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: return "".join( "--" + self.boundary - + "\n" + + "\r\n" + part._binary_headers.decode(encoding, errors) + part.decode() for part, _e, _te in self._parts diff --git a/tests/test_web_response.py b/tests/test_web_response.py index f8cf233e148..493e5e66f27 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -1063,7 +1063,7 @@ def read(self, size: int = -1) -> bytes: (BodyPartReader(b"x", CIMultiDictProxy(CIMultiDict()), mock.Mock()), None), ( mpwriter, - "--x\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\ntest", + "--x\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 4\r\n\r\ntest", ), ), )