This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zbysz
Recipients eric.smith, serhiy.storchaka, veky, zbysz
Date 2021-06-27.10:29:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624789769.99.0.257757860591.issue44452@roundup.psfhosted.org>
In-reply-to
Content
> It doesn't make sense to "concatenate" one absolute path to another.

Please see the original description of the issue, or Serhiy's example. I was thinking about about a case where paths are resolved relative to a container root in a filesystem. Serhiy brings up the case of a web server which concatenates paths from one namespace (URLs) to paths from another (fs paths).

> / has a simple explanation: if you start at /foo, and then do cd bar, you'll end up in /foo/bar. But if you start at /foo, and then do cd /bar, you'll end up in /bar.

You are thinking about a user doing operations in a shell. The two cases described are precisely NOT like this. In both examples, no matter what the path is, it is not allowed to go above the "root of the namespace". I.e. if you start at "/foo", and concatenate "/bar", you end up in "/foo/bar". If you are looking up "https://example.com/some/path", you want "/srv/www/some/path", etc.

>  what to do with C:\foo\bar, C:foo\bar, \\?\c\foo\bar, etc?

I think that with those paths there is no solution. They already don't work in any reasonable way:

>>> pathlib.Path('/asdf') / ("C:/some/path")                                                                          
PosixPath('/asdf/C:/some/path')
>>> pathlib.Path('C:\\asdf') / ("C:/some/path")                                                                       
PosixPath('C:\\asdf/C:/some/path')

Windows paths make no sense in the context of combination of namespaces and path concatenation, so I think it's fine to keep current behaviour (whatever it exactly is) for them. While the UNIX paths were designed to allow arbitrary nesting, the Windows paths were designed to always allow per-volume operations. The two concepts cannot be combined.

> In any case you need to have some validation to disallow "..".

Yes, that is a good point. In my code I do some validation that disallows ".." early on. But I think that the hypothetical //-operator should reject paths with "..".

> But lstrip('/') works well here. 

It kind of does, but
- it's rather verbose
- it breaks the order, because it's on the right of the argument.

I'll write to python-ideas.
History
Date User Action Args
2021-06-27 10:29:30zbyszsetrecipients: + zbysz, eric.smith, serhiy.storchaka, veky
2021-06-27 10:29:29zbyszsetmessageid: <1624789769.99.0.257757860591.issue44452@roundup.psfhosted.org>
2021-06-27 10:29:29zbyszlinkissue44452 messages
2021-06-27 10:29:29zbyszcreate