diff -r 06cf4044a11a Lib/pathlib.py --- a/Lib/pathlib.py Sat Aug 09 09:34:25 2014 +0300 +++ b/Lib/pathlib.py Sat Aug 09 14:52:29 2014 +0700 @@ -50,6 +50,8 @@ self.join = self.sep.join def parse_parts(self, parts): + if any(map(lambda arg: '\0' in arg, parts)): + raise TypeError("embedded NUL character") parsed = [] sep = self.sep altsep = self.altsep diff -r 06cf4044a11a Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py Sat Aug 09 09:34:25 2014 +0300 +++ b/Lib/test/test_pathlib.py Sat Aug 09 14:52:29 2014 +0700 @@ -1125,6 +1125,11 @@ # UNC paths are never reserved self.assertIs(False, P('//my/share/nul/con/aux').is_reserved()) + def test_forbid_embedded_nul(self): + P = self.cls + for arg in [('/foo/\0bar'), (P('/foo'), '/\0bar')]: + self.assertRaises(TypeError, P, *arg) + class PurePathTest(_BasePurePathTest, unittest.TestCase): cls = pathlib.PurePath