(original) (raw)
diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst --- a/Doc/library/os.path.rst +++ b/Doc/library/os.path.rst @@ -261,16 +261,24 @@ the :mod:`glob` module.) .. function:: normpath(path) Normalize a pathname by collapsing redundant separators and up-level references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all become ``A/B``. This string manipulation may change the meaning of a path that contains symbolic links. On Windows, it converts forward slashes to backward slashes. To normalize case, use :func:`normcase`. + .. note:: + + On POSIX systems, in accordance with `IEEE Std 1003.1™, 2013 Edition; 4.12 + Pathname Resolution `_, + double-slashes at the start of a path are allowed and represent the root + directory, and more than two slashes at the start of a path are treated as + a single slash and normalized as such. + .. function:: realpath(path) Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system). .. function:: relpath(path, start=os.curdir) diff --git a/Lib/posixpath.py b/Lib/posixpath.py --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -327,16 +327,17 @@ def normpath(path): empty = '' dot = '.' dotdot = '..' if path == empty: return dot initial_slashes = path.startswith(sep) # POSIX allows one or two initial slashes, but treats three or more # as single slash. + # (see http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1\_chap04.html#tag\_04\_12) if (initial_slashes and path.startswith(sep*2) and not path.startswith(sep*3)): initial_slashes = 2 comps = path.split(sep) new_comps = [] for comp in comps: if comp in (empty, dot): continue