Issue #19092 - Raise a correct exception when cgi.FieldStorage is given an

invalid file-obj. Also use __bool__ to determine the bool of the FieldStorage
object.
This commit is contained in:
Senthil Kumaran 2014-01-11 22:20:16 -08:00
parent 5636eb7b93
commit b4cbb92fbe
3 changed files with 22 additions and 2 deletions

View file

@ -137,6 +137,13 @@ class CgiTests(unittest.TestCase):
fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue'))
self.assertTrue(fs)
def test_fieldstorage_invalid(self):
self.assertRaises(TypeError, cgi.FieldStorage, "not-a-file-obj",
environ={"REQUEST_METHOD":"PUT"})
self.assertRaises(TypeError, cgi.FieldStorage, "foo", "bar")
fs = cgi.FieldStorage(headers={'content-type':'text/plain'})
self.assertRaises(TypeError, bool, fs)
def test_escape(self):
# cgi.escape() is deprecated.
with warnings.catch_warnings():