Skip to content

Commit bd22869

Browse files
Remove extraneous calls to .strip() in Chunked Encoding
To be valid chunked encoding we should not be removing any whitespace as the standard does not allow for optional whitespace. If whitespace is encountered in the wrong place, it should lead to a 400 Bad Request instead.
1 parent d9bdfa0 commit bd22869

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/waitress/receiver.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def received(self, s):
135135
line = s[:pos]
136136
s = s[pos + 2 :]
137137
self.control_line = b""
138-
line = line.strip()
139138

140139
if line:
141140
# Begin a new chunk.
@@ -153,9 +152,6 @@ def received(self, s):
153152

154153
line = line[:semi]
155154

156-
# Remove any whitespace
157-
line = line.strip()
158-
159155
if not ONLY_HEXDIG_RE.match(line):
160156
self.error = BadRequest("Invalid chunk size")
161157
self.all_chunks_received = True
@@ -164,7 +160,7 @@ def received(self, s):
164160

165161
# Can not fail due to matching against the regular
166162
# expression above
167-
sz = int(line.strip(), 16) # hexadecimal
163+
sz = int(line, 16) # hexadecimal
168164

169165
if sz > 0:
170166
# Start a new chunk.

tests/test_receiver.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ def test_received_valid_extensions(self, valid_extension):
262262
assert result == len(data)
263263
assert inst.error == None
264264

265-
@pytest.mark.parametrize("invalid_size", [b"0x04", b"+0x04", b"x04", b"+04"])
265+
@pytest.mark.parametrize(
266+
"invalid_size", [b"0x04", b"+0x04", b"x04", b"+04", b" 04", b" 0x04"]
267+
)
266268
def test_received_invalid_size(self, invalid_size):
267269
from waitress.utilities import BadRequest
268270

0 commit comments

Comments
 (0)