diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-03-19 07:04:59 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-03-19 07:04:59 (GMT) |
commit | 1cd4ff6284071140826c8cfbb4771e4e395b774a (patch) | |
tree | 7bed1b761c2fc333f00af76cec1e7463c312c330 | |
parent | adcb6545194abdbefa47e5377367041634f1577c (diff) | |
download | cpython-1cd4ff6284071140826c8cfbb4771e4e395b774a.zip cpython-1cd4ff6284071140826c8cfbb4771e4e395b774a.tar.gz cpython-1cd4ff6284071140826c8cfbb4771e4e395b774a.tar.bz2 |
Issue #26560: Avoid potential ValueError in BaseHandler.start_response
Initial patch by Peter Inglesby.
-rw-r--r-- | Lib/test/test_wsgiref.py | 21 | ||||
-rw-r--r-- | Lib/wsgiref/handlers.py | 2 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 8cca595..3f800ef 100644 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -166,6 +166,27 @@ class IntegrationTests(TestCase): " be of type list: <class 'tuple'>" ) + def test_status_validation_errors(self): + def create_bad_app(status): + def bad_app(environ, start_response): + start_response(status, [("Content-Type", "text/plain; charset=utf-8")]) + return [b"Hello, world!"] + return bad_app + + tests = [ + ('200', 'AssertionError: Status must be at least 4 characters'), + ('20X OK', 'AssertionError: Status message must begin w/3-digit code'), + ('200OK', 'AssertionError: Status message must have a space after code'), + ] + + for status, exc_message in tests: + with self.subTest(status=status): + out, err = run_amock(create_bad_app(status)) + self.assertTrue(out.endswith( + b"A server error occurred. Please contact the administrator." + )) + self.assertEqual(err.splitlines()[-2], exc_message) + def test_wsgi_input(self): def bad_app(e,s): e["wsgi.input"].read() diff --git a/Lib/wsgiref/handlers.py b/Lib/wsgiref/handlers.py index 63d5993..acb3547 100644 --- a/Lib/wsgiref/handlers.py +++ b/Lib/wsgiref/handlers.py @@ -226,7 +226,7 @@ class BaseHandler: self.headers = self.headers_class(headers) status = self._convert_string_type(status, "Status") assert len(status)>=4,"Status must be at least 4 characters" - assert int(status[:3]),"Status message must begin w/3-digit code" + assert status[:3].isdigit(), "Status message must begin w/3-digit code" assert status[3]==" ", "Status message must have a space after code" if __debug__: @@ -91,6 +91,9 @@ Core and Builtins Library ------- +- Issue #26560: Avoid potential ValueError in BaseHandler.start_response. + Initial patch by Peter Inglesby. + - Issue #26313: ssl.py _load_windows_store_certs fails if windows cert store is empty. Patch by Baji. |