summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_posix.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-20 07:12:28 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-20 07:12:28 (GMT)
commit7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48 (patch)
tree0cecdabe5db216090cd9fb763bf3cd6c3b2165e3 /Lib/test/test_posix.py
parente3037e114509913874a28746f5e05780919e909a (diff)
parent2b0d2007a1a51a15a67dc7297cf5e21c8767b563 (diff)
downloadcpython-7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48.zip
cpython-7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48.tar.gz
cpython-7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48.tar.bz2
Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them. Removed no longer used _PyUnicode_HasNULChars().
Diffstat (limited to 'Lib/test/test_posix.py')
-rw-r--r--Lib/test/test_posix.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index d49cd92..77e5b0c4 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -1168,6 +1168,42 @@ class PosixTester(unittest.TestCase):
else:
self.fail("No valid path_error2() test for os." + name)
+ def test_path_with_null_character(self):
+ fn = support.TESTFN
+ fn_with_NUL = fn + '\0'
+ self.addCleanup(support.unlink, fn)
+ support.unlink(fn)
+ fd = None
+ try:
+ with self.assertRaises(ValueError):
+ fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
+ finally:
+ if fd is not None:
+ os.close(fd)
+ self.assertFalse(os.path.exists(fn))
+ self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
+ self.assertFalse(os.path.exists(fn))
+ open(fn, 'wb').close()
+ self.assertRaises(ValueError, os.stat, fn_with_NUL)
+
+ def test_path_with_null_byte(self):
+ fn = os.fsencode(support.TESTFN)
+ fn_with_NUL = fn + b'\0'
+ self.addCleanup(support.unlink, fn)
+ support.unlink(fn)
+ fd = None
+ try:
+ with self.assertRaises(ValueError):
+ fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
+ finally:
+ if fd is not None:
+ os.close(fd)
+ self.assertFalse(os.path.exists(fn))
+ self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
+ self.assertFalse(os.path.exists(fn))
+ open(fn, 'wb').close()
+ self.assertRaises(ValueError, os.stat, fn_with_NUL)
+
class PosixGroupsTester(unittest.TestCase):
def setUp(self):