diff options
-rw-r--r-- | waitress/parser.py | 5 | ||||
-rw-r--r-- | waitress/tests/test_parser.py | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/waitress/parser.py b/waitress/parser.py index dec96f6..4261fa3 100644 --- a/waitress/parser.py +++ b/waitress/parser.py @@ -251,7 +251,10 @@ class HTTPRequestParser(object): def split_uri(uri): # urlsplit handles byte input by returning bytes on py3, so # scheme, netloc, path, query, and fragment are bytes - scheme, netloc, path, query, fragment = urlparse.urlsplit(uri) + try: + scheme, netloc, path, query, fragment = urlparse.urlsplit(uri) + except UnicodeError: + raise ParsingError('Bad URI') return ( tostr(scheme), tostr(netloc), diff --git a/waitress/tests/test_parser.py b/waitress/tests/test_parser.py index ed3a66c..5805408 100644 --- a/waitress/tests/test_parser.py +++ b/waitress/tests/test_parser.py @@ -249,6 +249,11 @@ class Test_split_uri(unittest.TestCase): self.assertEqual(self.proxy_scheme, 'https') self.assertEqual(self.proxy_netloc, 'localhost:8080') + def test_split_uri_unicode_error_raises_parsing_error(self): + # See https://github.com/Pylons/waitress/issues/64 + from waitress.parser import ParsingError + self.assertRaises(ParsingError, self._callFUT, b'/\xd0') + class Test_get_header_lines(unittest.TestCase): def _callFUT(self, data): |