mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#7909: the prefixes \\.\ and \\?\ indicate special Windows paths, do not try to manipulate them. See http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx for details.
This commit is contained in:
parent
a8867b4173
commit
cfb68218b7
3 changed files with 19 additions and 0 deletions
|
@ -71,6 +71,12 @@ def _get_colon(path):
|
|||
else:
|
||||
return ':'
|
||||
|
||||
def _get_special(path):
|
||||
if isinstance(path, bytes):
|
||||
return (b'\\\\.\\', b'\\\\?\\')
|
||||
else:
|
||||
return ('\\\\.\\', '\\\\?\\')
|
||||
|
||||
# Normalize the case of a pathname and map slashes to backslashes.
|
||||
# Other normalizations (such as optimizing '../' away) are not done
|
||||
# (this is done by normpath).
|
||||
|
@ -524,6 +530,13 @@ def normpath(path):
|
|||
"""Normalize path, eliminating double slashes, etc."""
|
||||
sep = _get_sep(path)
|
||||
dotdot = _get_dot(path) * 2
|
||||
special_prefixes = _get_special(path)
|
||||
if path.startswith(special_prefixes):
|
||||
# in the case of paths with these prefixes:
|
||||
# \\.\ -> device names
|
||||
# \\?\ -> literal paths
|
||||
# do not do any normalization, but return the path unchanged
|
||||
return path
|
||||
path = path.replace(_get_altsep(path), sep)
|
||||
prefix, path = splitdrive(path)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue