Skip to content

ensure our boundary matches: improve the message #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down