|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import os
|
4 | 5 | import random
|
5 | 6 | import sys
|
|
9 | 10 | from typing import TYPE_CHECKING, cast
|
10 | 11 | from unittest.mock import Mock
|
11 | 12 |
|
| 13 | +import pytest |
12 | 14 | import yaml
|
13 | 15 |
|
14 | 16 | from python_multipart.decoders import Base64Decoder, QuotedPrintableDecoder
|
@@ -1248,6 +1250,30 @@ def on_file(f: FileProtocol) -> None:
|
1248 | 1250 | f = FormParser("multipart/form-data", on_field=Mock(), on_file=on_file, boundary="boundary")
|
1249 | 1251 | f.write(data.encode("latin-1"))
|
1250 | 1252 |
|
| 1253 | + @pytest.fixture(autouse=True) |
| 1254 | + def inject_fixtures(self, caplog: pytest.LogCaptureFixture) -> None: |
| 1255 | + self._caplog = caplog |
| 1256 | + |
| 1257 | + def test_multipart_parser_data_end_with_crlf_without_warnings(self) -> None: |
| 1258 | + """This test makes sure that the parser does not handle when the data ends with a CRLF.""" |
| 1259 | + data = ( |
| 1260 | + "--boundary\r\n" |
| 1261 | + 'Content-Disposition: form-data; name="file"; filename="filename.txt"\r\n' |
| 1262 | + "Content-Type: text/plain\r\n\r\n" |
| 1263 | + "hello\r\n" |
| 1264 | + "--boundary--\r\n" |
| 1265 | + ) |
| 1266 | + |
| 1267 | + files: list[File] = [] |
| 1268 | + |
| 1269 | + def on_file(f: FileProtocol) -> None: |
| 1270 | + files.append(cast(File, f)) |
| 1271 | + |
| 1272 | + f = FormParser("multipart/form-data", on_field=Mock(), on_file=on_file, boundary="boundary") |
| 1273 | + with self._caplog.at_level(logging.WARNING): |
| 1274 | + f.write(data.encode("latin-1")) |
| 1275 | + assert len(self._caplog.records) == 0 |
| 1276 | + |
1251 | 1277 | def test_max_size_multipart(self) -> None:
|
1252 | 1278 | # Load test data.
|
1253 | 1279 | test_file = "single_field_single_file.http"
|
|
0 commit comments