[issue46654] urllib.request.urlopen doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Barney Gale


Barney Gale  added the comment:

Agree with the previous analysis. Just noting that:

>>> nturl2path.pathname2url('host\\share\\test.py')
'host/share/test.py'

So four slashes are produced by the urllib code, whereas pathlib only produces 
two.

According to wikipedia, both the two- and four-slash variants are in active 
usage. As we can see within Python itself! :P

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46654] urllib.request.urlopen doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Eryk Sun


Eryk Sun  added the comment:

> file://server/host/file.ext on windows, even though 
> file:server/host/file.ext open just fine.

For r"\\host\share\test.py", the two slash conversion 
"file://host/share/test.py" is correct according to RFC80889 "E.3.1.  URI 
with Authority" [1]. In this case, req.host is "host", and req.selector is 
"/share/test.py". 

The four slash version "file:host/share/test.py" is a known variant for a 
converted UNC path, as noted in RFC8089 "E.3.2.  URI with UNC Path". In 
this case, req.host is an empty string, and req.selector is 
"//host/share/test.py". There's another variant that uses 5 slashes for a UNC 
path, but urllib (or url2pathname) doesn't support it.

---
[1] https://datatracker.ietf.org/doc/html/rfc8089

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46654] urllib.request.urlopen doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Eryk Sun


Eryk Sun  added the comment:

In FileHandler.file_open(), req.host is the host name, which is either None or 
an empty string for a local drive path such as, respectively, 
"file:/Z:/test.py" or "file:///Z:/test.py". The value of req.selector never 
starts with "//", for which file_open() checks, but rather a single slash, such 
as "/Z:/test.py" or "/share/test.py". This is a bug in file_open(). Due to this 
bug, it always calls self.open_local_file(req), even if req.host isn't local. 
The distinction shouldn't matter in Windows, which supports UNC paths, but 
POSIX has to open a path on the local machine (possibly a mount point for a 
remote path, but that's irrelevant). In POSIX, if the local machine 
coincidentally has the req.selector path, then the os.stat() and open() calls 
will succeed with a bogus result.

For "file://host/share/test.py", req.selector is "/share/test.py". In Windows, 
url2pathname() converts this to r"\share\test.py", which is relative to the 
drive of the process current working directory. This is a bug in 
open_local_file() on Windows. For it to work correctly, req.host has to be 
joined back with req.selector as the UNC path "//host/share/test.py". Of 
course, this need not be a local file in Windows, so Windows should be exempted 
from the local file limitation in file_open().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46654] urllib.request.urlopen doesn't handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with additional slashes)

2022-02-05 Thread Mike Auty


Change by Mike Auty :


--
title: file_open doesn't handle UNC paths produced by pathlib's resolve() (but 
can handle UNC paths with additional slashes) -> urllib.request.urlopen doesn't 
handle UNC paths produced by pathlib's resolve() (but can handle UNC paths with 
additional slashes)

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com