mirror of
https://github.com/python/cpython.git
synced 2025-08-09 03:19:15 +00:00
[3.12] GH-110488: Fix two small issues in pathlib.PurePath.with_name()
(GH-110651) (#110678)
Ensure that `PurePath('foo/a').with_name('.')` raises `ValueError`
Ensure that `PureWindowsPath('foo/a').with_name('a:b')` does not raise
`ValueError`.
(cherry picked from commit b5f7777cb3
)
This commit is contained in:
parent
be381b5df5
commit
9ffef4d797
3 changed files with 15 additions and 6 deletions
|
@ -630,8 +630,7 @@ class PurePath(object):
|
|||
if not self.name:
|
||||
raise ValueError("%r has an empty name" % (self,))
|
||||
f = self._flavour
|
||||
drv, root, tail = f.splitroot(name)
|
||||
if drv or root or not tail or f.sep in tail or (f.altsep and f.altsep in tail):
|
||||
if not name or f.sep in name or (f.altsep and f.altsep in name) or name == '.':
|
||||
raise ValueError("Invalid name %r" % (name))
|
||||
return self._from_parsed_parts(self.drive, self.root,
|
||||
self._tail[:-1] + [name])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue