summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-01-29 17:36:34 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-01-29 17:36:34 (GMT)
commit1334884ff2f5a3968e6a26157f869b4ca5de189b (patch)
tree6cd82b8fa2964ad30b617cac8d0eaf98890d82c0 /Lib/test
parentc875d2032bf363da5e9e50928330f5ee2aa2fda2 (diff)
downloadcpython-1334884ff2f5a3968e6a26157f869b4ca5de189b.zip
cpython-1334884ff2f5a3968e6a26157f869b4ca5de189b.tar.gz
cpython-1334884ff2f5a3968e6a26157f869b4ca5de189b.tar.bz2
Issue #13848: open() and the FileIO constructor now check for NUL characters in the file name.
Patch by Hynek Schlawack.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_fileio.py5
-rw-r--r--Lib/test/test_io.py5
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 103365d..3588fb4 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -305,6 +305,11 @@ class OtherFileTests(unittest.TestCase):
finally:
os.unlink(TESTFN)
+ def testConstructorHandlesNULChars(self):
+ fn_with_NUL = 'foo\0bar'
+ self.assertRaises(TypeError, _FileIO, fn_with_NUL, 'w')
+ self.assertRaises(TypeError, _FileIO, bytes(fn_with_NUL, 'ascii'), 'w')
+
def testInvalidFd(self):
self.assertRaises(ValueError, _FileIO, -10)
self.assertRaises(OSError, _FileIO, make_bad_fd())
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index df7ca15..ea82cea 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -363,6 +363,11 @@ class IOTest(unittest.TestCase):
self.assertRaises(exc, fp.seek, 1, self.SEEK_CUR)
self.assertRaises(exc, fp.seek, -1, self.SEEK_END)
+ def test_open_handles_NUL_chars(self):
+ fn_with_NUL = 'foo\0bar'
+ self.assertRaises(TypeError, self.open, fn_with_NUL, 'w')
+ self.assertRaises(TypeError, self.open, bytes(fn_with_NUL, 'ascii'), 'w')
+
def test_raw_file_io(self):
with self.open(support.TESTFN, "wb", buffering=0) as f:
self.assertEqual(f.readable(), False)