Skip to content

Commit 4fa68ab

Browse files
committed
raise an ValueError in getvalue() on closed StringIO (closes #12161)
Thanks for Catalin Iacob for the patch.
1 parent dbfba16 commit 4fa68ab

4 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/StringIO.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def getvalue(self):
266266
8th bit) will cause a UnicodeError to be raised when getvalue()
267267
is called.
268268
"""
269+
_complain_ifclosed(self.closed)
269270
if self.buflist:
270271
self.buf += ''.join(self.buflist)
271272
self.buflist = []

Lib/test/test_StringIO.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def test_iterator(self):
100100
self._fp.close()
101101
self.assertRaises(ValueError, self._fp.next)
102102

103+
def test_getvalue(self):
104+
self._fp.close()
105+
self.assertRaises(ValueError, self._fp.getvalue)
106+
103107
class TestStringIO(TestGenericStringIO):
104108
MODULE = StringIO
105109

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ Eric Huss
382382
Jeremy Hylton
383383
Gerhard Häring
384384
Fredrik Håård
385+
Catalin Iacob
385386
Mihai Ibanescu
386387
Lars Immisch
387388
Bobby Impollonia

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Core and Builtins
8383
Library
8484
-------
8585

86+
- Issue #12161: Cause StringIO.getvalue() to raise a ValueError when used on a
87+
closed StringIO instance.
88+
8689
- Issue #12182: Fix pydoc.HTMLDoc.multicolumn() if Python uses the new (true)
8790
division (python -Qnew). Patch written by Ralf W. Grosse-Kunstleve.
8891

0 commit comments

Comments
 (0)