From 97f87ec13e9f97f31bef35f1d5e3bb00fda47b1d Mon Sep 17 00:00:00 2001 From: Vaclav Rehak Date: Fri, 26 Apr 2024 13:54:06 +0200 Subject: [PATCH] Fix InvalidHTTPVersion exception str method Fixes: #3195 --- gunicorn/http/errors.py | 2 +- tests/test_http.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gunicorn/http/errors.py b/gunicorn/http/errors.py index 340f0473c..1e3c5e752 100644 --- a/gunicorn/http/errors.py +++ b/gunicorn/http/errors.py @@ -53,7 +53,7 @@ def __init__(self, version): self.version = version def __str__(self): - return "Invalid HTTP Version: %r" % self.version + return "Invalid HTTP Version: %r" % (self.version,) class InvalidHeader(ParseException): diff --git a/tests/test_http.py b/tests/test_http.py index 0eb694601..f0ddc3bb2 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -9,7 +9,7 @@ from gunicorn.http.body import Body, LengthReader, EOFReader from gunicorn.http.wsgi import Response from gunicorn.http.unreader import Unreader, IterUnreader, SocketUnreader -from gunicorn.http.errors import InvalidHeader, InvalidHeaderName +from gunicorn.http.errors import InvalidHeader, InvalidHeaderName, InvalidHTTPVersion from gunicorn.http.message import TOKEN_RE @@ -238,3 +238,8 @@ def test_eof_reader_read_invalid_size(): reader.read([100]) with pytest.raises(ValueError): reader.read(-100) + + +def test_invalid_http_version_error(): + assert str(InvalidHTTPVersion('foo')) == "Invalid HTTP Version: 'foo'" + assert str(InvalidHTTPVersion((2, 1))) == 'Invalid HTTP Version: (2, 1)'