classification
Title: pathlib.PurePath.with_suffix() allows creation of otherwise impossible paths
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: july, pitrou, python-dev, r.david.murray
Priority: normal Keywords:

Created on 2014-01-02 20:29 by july, last changed 2014-01-02 23:08 by pitrou. This issue is now closed.

Messages (4)
msg207185 - (view) Author: July Tikhonov (july) * Date: 2014-01-02 20:29
This is not a real-world example, but it brokes some invariant (part of path must not contain separator):

>>> pathlib.PurePath('/a/b.c.d').with_suffix('///')
PurePosixPath('/a/b.c///')
>>> pathlib.PurePath('/a/b.c.d').with_suffix('/not/split/into/parts').parts
('/', 'a', 'b.c/not/split/into/parts')

I think these cases should raise an error.

I would also like to consider the following to be an error, since the argument of with_suffix() is not exactly a suffix:

>>> PurePath('/a/b.c.d').with_suffix('e')
PurePosixPath('/a/b.ce')

but I'm far less sure in this case.
msg207196 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-02 22:52
Thank you for reporting this! You're right, this is a bug.
msg207197 - (view) Author: Roundup Robot (python-dev) Date: 2014-01-02 23:07
New changeset ef2b2ddd27c8 by Antoine Pitrou in branch 'default':
Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix.
http://hg.python.org/cpython/rev/ef2b2ddd27c8
msg207198 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-02 23:08
I've committed a fix: ValueError is now raised for invalid suffixes.
History
Date User Action Args
2014-01-02 23:08:25pitrousetstatus: open -> closed
versions: - Python 3.5
messages: + msg207198

resolution: fixed
stage: resolved
2014-01-02 23:07:36python-devsetnosy: + python-dev
messages: + msg207197
2014-01-02 22:52:39pitrousetmessages: + msg207196
2014-01-02 20:54:13r.david.murraysetnosy: + r.david.murray
2014-01-02 20:33:27julysettype: behavior
2014-01-02 20:29:00julycreate