Issue #13848: open() and the FileIO constructor now check for NUL characters in the file name.
Patch by Hynek Schlawack.
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 @@
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)