[issue22299] resolve() on Windows makes some pathological paths unusable
eryksun
report at bugs.python.org
Sat Sep 6 03:23:36 CEST 2014
eryksun added the comment:
Maybe for an extended path it could try _getfinalpathname without the prefix. If it isn't a valid path or the result isn't the same as _getfinalpathname including the prefix, then skip calling _ext_to_normal. For example:
def resolve(self, path):
s = str(path)
if not s:
return os.getcwd()
if _getfinalpathname is not None:
prefix, t = self._split_extended_path(s)
s = _getfinalpathname(s)
if prefix:
try:
if _getfinalpathname(t) != s:
return s
except FileNotFoundError:
return s
return self._ext_to_normal(s)
# Means fallback on absolute
return None
The 'foo.' path in this issue would keep the prefix:
>>> Path('//?/C:/foo.').resolve()
WindowsPath('//?/C:/foo.')
>>> Path('//?/UNC/server/C$/foo.').resolve()
WindowsPath('//?/UNC/server/C$/foo.')
But regular paths would remove the prefix:
>>> Path('//?/C:/bar').resolve()
WindowsPath('C:/bar')
>>> Path('//?/UNC/server/C$/bar').resolve()
WindowsPath('//server/C$/bar')
On a related note, _split_extended_path only looks for uppercase "UNC", which makes the above resolve method fail:
>>> Path('//?/unc/server/C$/bar').resolve()
WindowsPath('//?/UNC/server/C$/bar')
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22299>
_______________________________________
More information about the Python-bugs-list
mailing list