summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-07-07 01:31:12 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-07-07 01:31:12 (GMT)
commit7084e736db318ba83a879e2e93e7c76264e48dbf (patch)
tree9cbd1206a5f55d5d23a50ff7b481db36b5a7e01c /Lib/pathlib.py
parent7bc5fb6916b59e9d6e491c8519e5affa98b8aa6c (diff)
downloadcpython-7084e736db318ba83a879e2e93e7c76264e48dbf.zip
cpython-7084e736db318ba83a879e2e93e7c76264e48dbf.tar.gz
cpython-7084e736db318ba83a879e2e93e7c76264e48dbf.tar.bz2
Issue #21714: Disallow the construction of invalid paths using Path.with_name(). Original patch by Antony Lee.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index d3d1af8..c1ec07a 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -749,6 +749,10 @@ class PurePath(object):
"""Return a new path with the file name changed."""
if not self.name:
raise ValueError("%r has an empty name" % (self,))
+ drv, root, parts = self._flavour.parse_parts((name,))
+ if (not name or name[-1] in [self._flavour.sep, self._flavour.altsep]
+ or drv or root or len(parts) != 1):
+ raise ValueError("Invalid name %r" % (name))
return self._from_parsed_parts(self._drv, self._root,
self._parts[:-1] + [name])