Benjamin Peterson avatar Benjamin Peterson committed 720804a

raise an ValueError in getvalue() on closed StringIO (closes #12161)

Thanks for Catalin Iacob for the patch.

Comments (0)

Files changed (4)

         8th bit) will cause a UnicodeError to be raised when getvalue()
         is called.
         """
+        _complain_ifclosed(self.closed)
         if self.buflist:
             self.buf += ''.join(self.buflist)
             self.buflist = []

Lib/test/test_StringIO.py

         self._fp.close()
         self.assertRaises(ValueError, self._fp.next)
 
+    def test_getvalue(self):
+        self._fp.close()
+        self.assertRaises(ValueError, self._fp.getvalue)
+
 class TestStringIO(TestGenericStringIO):
     MODULE = StringIO
 
 Jeremy Hylton
 Gerhard Häring
 Fredrik Håård
+Catalin Iacob
 Mihai Ibanescu
 Lars Immisch
 Bobby Impollonia
 Library
 -------
 
+- Issue #12161: Cause StringIO.getvalue() to raise a ValueError when used on a
+  closed StringIO instance.
+
 - Issue #12182: Fix pydoc.HTMLDoc.multicolumn() if Python uses the new (true)
   division (python -Qnew). Patch written by Ralf W. Grosse-Kunstleve.
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.