mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
Issue #21714: Disallow the construction of invalid paths using Path.with_name(). Original patch by Antony Lee.
This commit is contained in:
parent
7bc5fb6916
commit
7084e736db
3 changed files with 15 additions and 0 deletions
|
@ -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])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue