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.

Title: os.path.join() fails if 2nd arg is a UNC path
Type: behavior Stage: test needed
Components: Documentation, Windows Versions: Python 2.6
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: BreamoreBoy, georg.brandl, georg.brandl, jpe, ocean-city, pekka.klarck
Priority: normal Keywords:

Created on 2005-05-26 20:45 by jpe, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg60752 - (view) Author: John Ehresman (jpe) * Date: 2005-05-26 20:45
os.path.join('c:', r'\\server\share') returns
c:\\server\share rather than \\server\share. 
Interestingly os.path.join('c:a', r'\\server\share')
returns r'\\server\share'.  IMHO, r'\\server\share'
should be returned in all cases.
msg60753 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-05-31 10:25
Logged In: YES 

This is a difficult issue, since as far as I recall Windows
allows two or more backslashes in a row in the middle of
normal paths.
msg60754 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-03 18:09
Logged In: YES 

I'd recommend not to change the behaviour, but add a note in
the docs that UNCs are not recognized as such in os.path.join.
msg60755 - (view) Author: John Ehresman (jpe) * Date: 2005-06-03 19:34
Logged In: YES 

If the current behavior is kept, then os.path.join can't be
relied upon to return the 2nd (or 3rd+) argument if that
argument is an absolute path.  This is one of the things I
rely on os.path.join to do and would need to write my own
version.  Also, the behavior is quite different if the first
agument contains more than simply the drive letter.

I know this is a difficult issue and that is why I would
like to see it fixed in the standard library.  My question
is whether there is a rationale for the current behavior.
msg87326 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-05-06 12:28
Seems to be fixed in python3.1. See #5799. This is not backported for
2.x yet. (Or it won't happen)
msg114995 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-26 16:00
Can the fix be backported to 2.7 or can this be closed?
msg114999 - (view) Author: John Ehresman (jpe) * Date: 2010-08-26 16:17
I say close it since it is a change in behavior and shouldn't go in a point release.  I'm happy to see it fixed in 3.1.
msg176988 - (view) Author: Pekka Klärck (pekka.klarck) Date: 2012-12-05 14:58
It seems that joining UNC path to a directory root fails:

Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ntpath import join
>>> join('c:\\', '\\\\server\\mount\\dir')

When the first argument contains also something else everything works fine:

>>> join('c:\\dir', '\\\\server\\mount\\dir')

I would say this is a bug. Obviously fixing this changes behavior, but I have hard time believing that anyone relies on the current buggy output.

On the other hand, I was today reported a bug in my software that was caused by this. Funny thing was that the bug was in code that was added as a workaround for issue #3426 (i.e. use `join(os.getcwdu(), path)` instead of `abspath(path)` when path is Unicode). Luckily adding another workaround for this issue is pretty easy.
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 42017
2012-12-05 14:58:42pekka.klarcksetnosy: + pekka.klarck
messages: + msg176988
2010-08-26 16:17:39jpesetstatus: open -> closed

messages: + msg114999
2010-08-26 16:00:17BreamoreBoysetnosy: + BreamoreBoy
messages: + msg114995
2009-05-06 12:28:53ocean-citysetnosy: + ocean-city
messages: + msg87326
2009-02-16 02:25:23ajaksu2setversions: + Python 2.6, - Python 2.4
nosy: + georg.brandl
assignee: georg.brandl
components: + Documentation
type: behavior
stage: test needed
2005-05-26 20:45:11jpecreate