[New-bugs-announce] [issue44810] nturl2path: drive definition

Nick report at bugs.python.org
Mon Aug 2 08:24:05 EDT 2021


New submission from Nick <novel8mail at gmail.com>:

Due some problem in a third-party package the `url2path` function from `nturl2path` got `a/"https://b"` (without `, `a`,`b` are just masks ) as the first and only argument.

In the function there is the following code ( https://github.com/python/cpython/blob/414dcb13aaa4fd42f264fdee47782dede5c83d6c/Lib/nturl2path.py#L30 ; current state of the `main` branch):
```
comp = url.split('|')
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
    error = 'Bad URL: ' + url
    raise OSError(error)
drive = comp[0][-1].upper()
```

As a result, the function decided that the file was located on the `S:` drive and returned the `S:\b` path without a warning.
To my mind, it is not right to take just the last letter as a drive letter because the returned path must be only for the specified URL and the unsupported ones must be marked as "bad" without any silent transformations.

----------
components: Windows
messages: 398761
nosy: NickVeld, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: nturl2path: drive definition
type: behavior
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44810>
_______________________________________


More information about the New-bugs-announce mailing list