Skip to content

Commit a16d0ee

Browse files
committed
refactor: Simpler first boundary check
The index=1 and index>=2 cases can be merged because "buffer[-1,1]" will return an empty slice, so "buffer[index-2, index] != CRLF" correctly detects bad stuff in front of the first boundary for both cases. This saves us a couple of ops on the good path and is also a bit easier to read.
1 parent b9e225e commit a16d0ee

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

multipart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def parse(
399399

400400
if index > -1:
401401
# Boundary must be at position zero, or start with CRLF
402-
if index > 0 and not (index >= 2 and buffer[index-2:index] == b"\r\n"):
402+
if index > 0 and buffer[index - 2 : index] != b"\r\n":
403403
raise ParserError("Unexpected byte in front of first boundary")
404404

405405
next_start = index + d_len

0 commit comments

Comments
 (0)