Skip to content

Commit fa6cecb

Browse files
committed
Adding test coverage for cgi.FieldStorage based on the scenario mentioned in issue #19097
1 parent 2bca9de commit fa6cecb

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_cgi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import tempfile
66
import unittest
77

8+
from collections import namedtuple
9+
810
class HackedSysModule:
911
# The regression test will have real values in sys.argv, which
1012
# will completely confuse the test of the cgi module
@@ -232,6 +234,14 @@ def __getattr__(self, name):
232234
# as long as the chunksize is 1 << 16.
233235
self.assertTrue(f.numcalls > 2)
234236

237+
def test_fieldstorage_invalid(self):
238+
fs = cgi.FieldStorage()
239+
self.assertFalse(fs)
240+
self.assertRaises(TypeError, bool(fs))
241+
self.assertEqual(list(fs), list(fs.keys()))
242+
fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue'))
243+
self.assertTrue(fs)
244+
235245
def test_fieldstorage_multipart(self):
236246
#Test basic FieldStorage multipart parsing
237247
env = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':'multipart/form-data; boundary=---------------------------721837373350705526688164684', 'CONTENT_LENGTH':'558'}

0 commit comments

Comments
 (0)