Skip to content

Commit 83191cb

Browse files
yecril23plKludex
andauthored
ensure our boundary matches: improve the message (#124)
* ensure our boundary matches: improve the message The error message should report expected actual mismatch. * improve syntax * use walrus operator * Oops, walrus not supported * reverse random paste * Test multi parser error boundary mismatch error message * Fix expected error message * rebase --------- Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
1 parent a169d93 commit 83191cb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

multipart/multipart.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def data_callback(name: CallbackName, end_i: int, remaining: bool = False) -> No
11501150
else:
11511151
# Check to ensure our boundary matches
11521152
if c != boundary[index + 2]:
1153-
msg = "Did not find boundary character %r at index " "%d" % (c, index + 2)
1153+
msg = "Expected boundary character %r, got %r at index %d" % (boundary[index + 2], c, index + 2)
11541154
self.logger.warning(msg)
11551155
e = MultipartParseError(msg)
11561156
e.offset = i

tests/test_multipart.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,12 @@ def test_bad_start_boundary(self) -> None:
10571057
self.make("boundary")
10581058
data = b"--boundaryfoobar"
10591059
with self.assertRaises(MultipartParseError):
1060-
i = self.f.write(data)
1060+
self.f.write(data)
1061+
1062+
self.make("boundary")
1063+
data = b"--Boundary\r\nfoobar"
1064+
with self.assertRaisesRegex(MultipartParseError, "Expected boundary character %r, got %r" % (b"b"[0], b"B"[0])):
1065+
self.f.write(data)
10611066

10621067
def test_octet_stream(self) -> None:
10631068
files: list[File] = []

0 commit comments

Comments
 (0)