Skip to content
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 tornado/httputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def parse_line(self, line: str) -> None:
if not line:
# Empty line, or the final CRLF of a header block.
return
if line[0].isspace():
if line[0] in HTTP_WHITESPACE:
# continuation of a multi-line header
# TODO(7.0): Remove support for line folding.
if self._last_key is None:
Expand Down
11 changes: 10 additions & 1 deletion tornado/test/httputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,22 @@ def test_multi_line(self):
[("Asdf", "qwer zxcv"), ("Foo", "bar baz"), ("Foo", "even more lines")],
)

def test_malformed_continuation(self):
def test_continuation(self):
data = "Foo: bar\r\n\tasdf"
headers = HTTPHeaders.parse(data)
self.assertEqual(headers["Foo"], "bar asdf")

# If the first line starts with whitespace, it's a
# continuation line with nothing to continue, so reject it
# (with a proper error).
data = " Foo: bar"
self.assertRaises(HTTPInputError, HTTPHeaders.parse, data)

# \f (formfeed) is whitespace according to str.isspace, but
# not according to the HTTP spec.
data = "Foo: bar\r\n\fasdf"
self.assertRaises(HTTPInputError, HTTPHeaders.parse, data)

def test_unicode_newlines(self):
# Ensure that only \r\n is recognized as a header separator, and not
# the other newline-like unicode characters.
Expand Down