mirror of
https://github.com/python/cpython.git
synced 2025-09-21 08:00:37 +00:00
GH-110488: Fix two small issues in pathlib.PurePath.with_name()
(#110651)
Ensure that `PurePath('foo/a').with_name('.')` raises `ValueError` Ensure that `PureWindowsPath('foo/a').with_name('a:b')` does not raise `ValueError`.
This commit is contained in:
parent
790ecf6302
commit
b5f7777cb3
3 changed files with 15 additions and 6 deletions
|
@ -603,8 +603,7 @@ class PurePath:
|
|||
if not self.name:
|
||||
raise ValueError("%r has an empty name" % (self,))
|
||||
m = self.pathmod
|
||||
drv, root, tail = m.splitroot(name)
|
||||
if drv or root or not tail or m.sep in tail or (m.altsep and m.altsep in tail):
|
||||
if not name or m.sep in name or (m.altsep and m.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