diff --git a/multipart/multipart.py b/multipart/multipart.py index 137d6e7..158b7e6 100644 --- a/multipart/multipart.py +++ b/multipart/multipart.py @@ -1150,7 +1150,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No else: # Check to ensure our boundary matches if c != boundary[index + 2]: - msg = "Did not find boundary character %r at index " "%d" % (c, index + 2) + msg = "Expected boundary character %r, got %r at index %d" % (boundary[index + 2], c, index + 2) self.logger.warning(msg) e = MultipartParseError(msg) e.offset = i diff --git a/tests/test_multipart.py b/tests/test_multipart.py index f55e228..b824f19 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -1057,7 +1057,12 @@ def test_bad_start_boundary(self) -> None: self.make("boundary") data = b"--boundaryfoobar" with self.assertRaises(MultipartParseError): - i = self.f.write(data) + self.f.write(data) + + self.make("boundary") + data = b"--Boundary\r\nfoobar" + with self.assertRaisesRegex(MultipartParseError, "Expected boundary character %r, got %r" % (b"b"[0], b"B"[0])): + self.f.write(data) def test_octet_stream(self) -> None: files: list[File] = []