Skip to content

Commit

Permalink
FileStorage.content_length does not fail if no length was provided (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Jun 8, 2023
2 parents 3a8de8d + a184111 commit bb24506
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Version 2.3.6

Unreleased

- ``FileStorage.content_length`` does not fail if the form data did not provide a
value. :issue:`2726`


Version 2.3.5
-------------
Expand Down
11 changes: 7 additions & 4 deletions src/werkzeug/datastructures/file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ def content_type(self):
@property
def content_length(self):
"""The content-length sent in the header. Usually not available"""
try:
return _plain_int(self.headers.get("content-length") or 0)
except ValueError:
return 0
if "content-length" in self.headers:
try:
return _plain_int(self.headers["content-length"])
except ValueError:
pass

return 0

@property
def mimetype(self):
Expand Down

0 comments on commit bb24506

Please sign in to comment.