summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-07-07 01:37:15 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-07-07 01:37:15 (GMT)
commite50dafcd636ba32db890600164698bb070d40d97 (patch)
treea5c1283b9830358f11b61d6bb624f82bb98f5c60 /Lib/pathlib.py
parent7084e736db318ba83a879e2e93e7c76264e48dbf (diff)
downloadcpython-e50dafcd636ba32db890600164698bb070d40d97.zip
cpython-e50dafcd636ba32db890600164698bb070d40d97.tar.gz
cpython-e50dafcd636ba32db890600164698bb070d40d97.tar.bz2
Issue #20639: calling Path.with_suffix('') allows removing the suffix again.
Patch by July Tikhonov.
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index c1ec07a..48b7031 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -759,11 +759,10 @@ class PurePath(object):
def with_suffix(self, suffix):
"""Return a new path with the file suffix changed (or added, if none)."""
# XXX if suffix is None, should the current suffix be removed?
- drv, root, parts = self._flavour.parse_parts((suffix,))
- if drv or root or len(parts) != 1:
+ f = self._flavour
+ if f.sep in suffix or f.altsep and f.altsep in suffix:
raise ValueError("Invalid suffix %r" % (suffix))
- suffix = parts[0]
- if not suffix.startswith('.'):
+ if suffix and not suffix.startswith('.') or suffix == '.':
raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
if not name: