Skip to content

Commit

Permalink
Correctly handle newline detection not only for open boundary but for…
Browse files Browse the repository at this point in the history
… close mark too (#3758)
  • Loading branch information
asvetlov authored May 13, 2019
1 parent 0ad5d90 commit 7531fee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,22 @@ async def _read_until_first_boundary(self) -> None:
if chunk == b'':
raise ValueError("Could not find starting boundary %r"
% (self._boundary))
if chunk.startswith(self._boundary):
newline = None
end_boundary = self._boundary + b'--'
if chunk.startswith(end_boundary):
_, newline = chunk.split(end_boundary, 1)
elif chunk.startswith(self._boundary):
_, newline = chunk.split(self._boundary, 1)
assert newline in (b'\r\n', b'\n')
if newline is not None:
assert newline in (b'\r\n', b'\n'), (newline,
chunk,
self._boundary)
self._newline = newline

chunk = chunk.rstrip()
if chunk == self._boundary:
return
elif chunk == self._boundary + b'--':
elif chunk == end_boundary:
self._at_eof = True
return

Expand Down

0 comments on commit 7531fee

Please sign in to comment.