GeezerVison is showing github.com — Handle CTE values case-insensitively · Kludex/python-multipart@b4e682c
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: python_multipart/multipart.py +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1665,7 +1665,9 @@ def on_headers_finished() -> None: |
1665 | 1665 | # Parse the given Content-Transfer-Encoding to determine what |
1666 | 1666 | # we need to do with the incoming data. |
1667 | 1667 | # TODO: check that we properly handle 8bit / 7bit encoding. |
1668 | | - transfer_encoding = headers.get(b"content-transfer-encoding", b"7bit") |
| 1668 | + # RFC 2045 section 6.1: Content-Transfer-Encoding values are case-insensitive. |
| 1669 | + # https://www.rfc-editor.org/rfc/rfc2045#section-6.1 |
| 1670 | + transfer_encoding = headers.get(b"content-transfer-encoding", b"7bit").lower() |
1669 | 1671 |
|
1670 | 1672 | if transfer_encoding in (b"binary", b"8bit", b"7bit"): |
1671 | 1673 | writer = f_multi |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/test_multipart.py +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1230,6 +1230,29 @@ def on_file(f: File) -> None: |
1230 | 1230 | f.finalize() |
1231 | 1231 | self.assert_file_data(files[0], b"Test") |
1232 | 1232 |
|
| 1233 | + def test_content_transfer_encoding_is_case_insensitive(self) -> None: |
| 1234 | + for content_transfer_encoding in (b"base64", b"BASE64", b"Base64"): |
| 1235 | + with self.subTest(content_transfer_encoding=content_transfer_encoding): |
| 1236 | + data = ( |
| 1237 | + b'----boundary\r\nContent-Disposition: form-data; name="file"; filename="test.txt"\r\n' |
| 1238 | + b"Content-Type: text/plain\r\n" |
| 1239 | + b"Content-Transfer-Encoding: " |
| 1240 | + + content_transfer_encoding |
| 1241 | + + b"\r\n\r\nVGVzdA==\r\n----boundary--\r\n" |
| 1242 | + ) |
| 1243 | + files: list[File] = [] |
| 1244 | + |
| 1245 | + f = FormParser( |
| 1246 | + "multipart/form-data", |
| 1247 | + None, |
| 1248 | + files.append, |
| 1249 | + boundary="--boundary", |
| 1250 | + ) |
| 1251 | + |
| 1252 | + f.write(data) |
| 1253 | + f.finalize() |
| 1254 | + self.assert_file_data(files[0], b"Test") |
| 1255 | + |
1233 | 1256 | def test_handles_None_fields(self) -> None: |
1234 | 1257 | fields: list[Field] = [] |
1235 | 1258 |
|
|