This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.normpath("//") returns //
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Fred Rolland, Jack.McCracken, Winterflower, abarry, acue, furkanonder, lemburg, lukasz.langa, miss-islington, nanjekyejoannah, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-02-10 14:58 by Fred Rolland, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
add-many-slash-path-note.patch Jack.McCracken, 2016-06-05 22:23 review
Pull Requests
URL Status Linked Edit
PR 20138 merged furkanonder, 2020-05-16 23:34
PR 27094 merged miss-islington, 2021-07-12 12:48
PR 27095 merged miss-islington, 2021-07-12 12:48
Messages (13)
msg260016 - (view) Author: Fred Rolland (Fred Rolland) Date: 2016-02-10 14:58
Hi,

os.path.normpath("//") returns '//'

I would expect to be '/'

>>> os.path.normpath("//")
'//'
>>> os.path.normpath("///")
'/'
>>> os.path.normpath("////")
'/'
msg260024 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-02-10 16:01
This is a duplicate of issue636648.

This is intended behavior. It was introduced in changeset 01d5b80a3c03.

From the POSIX Specification [1]:

"""
A pathname consisting of a single <slash> shall resolve to the root directory of the process. A null pathname shall not be successfully resolved. If a pathname begins with two successive <slash> characters, the first component following the leading <slash> characters may be interpreted in an implementation-defined manner, although more than two leading <slash> characters shall be treated as a single <slash> character.
"""

See also Stack Overflow and Stack Exchange questions: [2], [3], [4].

May be we should add an explanation and a link to the specification in the documentation and comments.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12
[2] http://stackoverflow.com/questions/7816818/why-doesnt-os-normapath-collapse-a-leading-double-slash
[3] http://unix.stackexchange.com/questions/12283/unix-difference-between-path-starting-with-and
[4] http://unix.stackexchange.com/questions/1910/how-does-linux-handle-multiple-consecutive-path-separators-home-username
msg265837 - (view) Author: Camilla Montonen (Winterflower) Date: 2016-05-18 20:41
Should the comment with the link to specification be added to Lib/posixpath.py? or Lib/os.py?
msg267400 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2016-06-05 07:59
I propose to add at least a statement like e.g. "In conformance to IEEE Std 1003.1™, 2013 Edition; 4.12 Pathname Resolution".

Because I had the same thought of a bug at first view, this because I did not find any hint in e.g. docs for 2.7.11. 

The reason to handle this thoroughly in my projects is the application of a path-matching library for generic unit tests, e.g. for bash scripts which require intensive PATH resolution. This has to be applied by the users of the library.

See "https://pypi.python.org/pypi/pyfilesysobjects", and  "https://pypi.python.org/pypi/epyunit" which requires intensive pattern matching of application provided pathnames, e.g. when it comes to automatic split of actual used PYTHONPATH items for a specific function/method, module, or package.

E.g. the user provides an 'intentional casual' pathname for drop-in unit tests(see epyunit),
  "os.sep + context.sys.path[x] + os.sep + 'rel-module-path'",
due to mixed relative and absolute paths resulting in leading 
  "os.sep + os.sep".  
The pattern match than fails, but it is not immediately clear for which reason.
msg267411 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-05 12:09
Could you provide a patch Arno-Can?

According to the comment in the configure script of GNU coreutils, the only POSIX platforms known for coreutils developers that have two distinct roots / and // are Cygwin, z/OS and dead Apollo DomainOS. Yet few exotic platforms are mentioned in the topic at http://comments.gmane.org/gmane.comp.standards.posix.austin.general/11947 .
msg267471 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2016-06-05 20:25
Hi Serhiy,
I am currently still investigating it for my own project. 

  https://stackoverflow.com/questions/37646103/posix-path-1003-1-examples-and-behaviour-for-foo-bar

Currently I do not have the build environment, so I can provide the text, but because I am a bit under pressure with finishing a larger pack of OpenSource projects currently I cannot manage to setup the environment.

So can do this eventually in 2-3Weeks.
msg267478 - (view) Author: Jack McCracken (Jack.McCracken) * Date: 2016-06-05 21:44
Hey all - I would love to write a patch :) Working on it!
msg267481 - (view) Author: Jack McCracken (Jack.McCracken) * Date: 2016-06-05 22:23
Here's the patch I made.
msg343661 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-05-27 17:01
@ Jack McCracken do you want to open a pull request for this?
msg369084 - (view) Author: Furkan Onder (furkanonder) * Date: 2020-05-16 23:33
PR has been sent!
msg397304 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2021-07-12 12:48
New changeset 66c5853406bbcccecf35372795078c0641a5f385 by Furkan Onder in branch 'main':
bpo-26329: update os.path.normpath documentation (GH-20138)
https://github.com/python/cpython/commit/66c5853406bbcccecf35372795078c0641a5f385
msg397321 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-12 15:08
New changeset 443db64f496d3988d20cfda2c3c2ceb6702df36f by Miss Islington (bot) in branch '3.10':
bpo-26329: update os.path.normpath documentation (GH-20138) (GH-27094)
https://github.com/python/cpython/commit/443db64f496d3988d20cfda2c3c2ceb6702df36f
msg397328 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-12 15:22
New changeset 47abf240365ddd54a91c6ac167900d4bf6806c4f by Miss Islington (bot) in branch '3.9':
bpo-26329: update os.path.normpath documentation (GH-20138) (#27095)
https://github.com/python/cpython/commit/47abf240365ddd54a91c6ac167900d4bf6806c4f
History
Date User Action Args
2022-04-11 14:58:27adminsetgithub: 70517
2021-07-12 15:23:31lukasz.langasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-12 15:22:37lukasz.langasetmessages: + msg397328
2021-07-12 15:08:06lukasz.langasetnosy: + lukasz.langa
messages: + msg397321
2021-07-12 12:48:26nanjekyejoannahsetmessages: + msg397304
2021-07-12 12:48:24miss-islingtonsetpull_requests: + pull_request25643
2021-07-12 12:48:18miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25642
2021-06-21 14:12:09iritkatrielsetversions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.5, Python 3.6
2020-05-16 23:34:22furkanondersetstage: needs patch -> patch review
pull_requests: + pull_request19444
2020-05-16 23:33:46furkanondersetnosy: + furkanonder
messages: + msg369084
2019-05-27 17:01:03nanjekyejoannahsetnosy: + nanjekyejoannah
messages: + msg343661
2016-06-05 22:23:42Jack.McCrackensetfiles: + add-many-slash-path-note.patch
keywords: + patch
messages: + msg267481
2016-06-05 21:44:23Jack.McCrackensetnosy: + Jack.McCracken
messages: + msg267478
2016-06-05 20:25:56acuesetmessages: + msg267471
2016-06-05 12:09:40serhiy.storchakasetmessages: + msg267411
2016-06-05 07:59:01acuesetnosy: + acue
messages: + msg267400
2016-05-18 20:41:12Winterflowersetmessages: + msg265837
2016-05-18 19:39:13Winterflowersetnosy: + Winterflower
2016-02-10 18:03:29serhiy.storchakasetassignee: serhiy.storchaka ->
2016-02-10 16:01:15serhiy.storchakasetnosy: + lemburg
messages: + msg260024
components: + Documentation, - Library (Lib)
2016-02-10 15:17:48abarrysetassignee: serhiy.storchaka

type: behavior
nosy: + serhiy.storchaka, abarry
stage: needs patch
2016-02-10 14:58:05Fred Rollandcreate