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.

Author Bruce.Leban
Recipients Bruce.Leban, elixir, gvanrossum, martin.panter, pitrou
Date 2013-11-04.00:27:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1383524830.07.0.240203386535.issue19456@psf.upfronthosting.co.za>
In-reply-to
Content
A non-UNC windows path consists of two parts: a drive and a conventional path. If the drive is left out, it's relative to the current drive. If the path part does not have a leading \ then it's relative to the current path on that drive. Note that Windows has a different working dir for every drive.

x\y.txt    # in dir x in current dir on current drive
\x\y.txt   # in dir x at root of current drive
E:x\y.txt  # in dir in current dir on drive E
E:\x\y.txt # in dir x at root of drive E

UNC paths are similar except \\server\share is used instead of X: and there are no relative paths, since the part after share always starts with a \.

Thus when joining paths, if the second path specifies a drive, then the result should include that drive, otherwise the drive from the first path should be used. The path parts should be combined with the standard logic.

Some additional test cases

tester("ntpath.join(r'C:/a/b/c/d', '/e/f')", 'C:\e\f')
tester("ntpath.join('//a/b/c/d', '/e/f')", '//a/b/e/f')
tester("ntpath.join('C:x/y', r'z')", r'C:x/y/z')
tester("ntpath.join('C:x/y', r'/z')", r'C:/z')

Andrei notes that the following is wrong but wonders what the correct answer is:

>>> ntpath.join('C:/a/b', 'D:x/y')
'C:/a/b\\D:x/y'

The /a/b part of the path is an absolute path on drive C and isn't "transferable" to another drive. So a reasonable result is simply 'D:x/y'. This matches Windows behavior. If on Windows you did

$ cd /D C:\a\b
$ cat D:x\y

it would ignore the current drive on C set by the first command and use the current drive on D.

tester("ntpath.join('C:/a/b', 'D:x/y')", r'D:x/y')
tester("ntpath.join('//c/a/b', 'D:x/y')", r'D:x/y')
History
Date User Action Args
2013-11-04 00:27:10Bruce.Lebansetrecipients: + Bruce.Leban, gvanrossum, pitrou, martin.panter, elixir
2013-11-04 00:27:10Bruce.Lebansetmessageid: <1383524830.07.0.240203386535.issue19456@psf.upfronthosting.co.za>
2013-11-04 00:27:10Bruce.Lebanlinkissue19456 messages
2013-11-04 00:27:09Bruce.Lebancreate