Skip to content

Commit

Permalink
Add header parsing tests with short headers
Browse files Browse the repository at this point in the history
While fixing the catastrophic backtracking a gap in tests led to a
potentially bad regex being considered that would have caused issues
with short header values.

This now adds a test to make sure we don't regress.
  • Loading branch information
digitalresistor committed Feb 2, 2020
1 parent ac0ca05 commit 2fe8e54
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions waitress/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,17 @@ def test_parse_header_multiple_values_extra_space(self):
self.assertIn("FOO", self.parser.headers)
self.assertEqual(self.parser.headers["FOO"], "abrowser/0.001 (C O M M E N T)")

def test_parse_header_short_values(self):
from waitress.parser import ParsingError

data = b"GET /foobar HTTP/1.1\r\none: 1\r\ntwo: 22\r\n"
self.parser.parse_header(data)

self.assertIn("ONE", self.parser.headers)
self.assertIn("TWO", self.parser.headers)
self.assertEqual(self.parser.headers["ONE"], "1")
self.assertEqual(self.parser.headers["TWO"], "22")


class Test_split_uri(unittest.TestCase):
def _callFUT(self, uri):
Expand Down

0 comments on commit 2fe8e54

Please # to comment.