Skip to content

Commit

Permalink
Add tests to make sure we don't strip non-RFC7230 whitespace from hea…
Browse files Browse the repository at this point in the history
…der values
  • Loading branch information
digitalresistor committed Feb 5, 2024
1 parent 430fa1c commit b5d1fb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ def test_parse_header_invalid_chars(self):
else: # pragma: nocover
self.assertTrue(False)

def test_parse_header_other_whitespace(self):
data = b"GET /foobar HTTP/1.1\r\nfoo: \xa0something\x85\r\n"
self.parser.parse_header(data)
self.assertEqual(self.parser.headers["FOO"], "\xa0something\x85")

def test_parse_header_empty(self):
data = b"GET /foobar HTTP/1.1\r\nfoo: bar\r\nempty:\r\n"
self.parser.parse_header(data)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def test_get_environment_values(self):
request.headers = {
"CONTENT_TYPE": "abc",
"CONTENT_LENGTH": "10",
"X_FOO": "BAR",
"X_FOO": "\xa0BAR\x85",
"CONNECTION": "close",
}
request.query = "abc"
Expand Down Expand Up @@ -830,7 +830,8 @@ def test_get_environment_values(self):
self.assertEqual(environ["REMOTE_PORT"], "39830")
self.assertEqual(environ["CONTENT_TYPE"], "abc")
self.assertEqual(environ["CONTENT_LENGTH"], "10")
self.assertEqual(environ["HTTP_X_FOO"], "BAR")
# Make sure we don't strip non RFC compliant whitespace
self.assertEqual(environ["HTTP_X_FOO"], "\xa0BAR\x85")
self.assertEqual(environ["wsgi.version"], (1, 0))
self.assertEqual(environ["wsgi.url_scheme"], "http")
self.assertEqual(environ["wsgi.errors"], sys.stderr)
Expand Down

0 comments on commit b5d1fb5

Please sign in to comment.