]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Change ntpath.join() so that join("d:/", "/whatever") returns
authorTim Peters <tim.peters@gmail.com>
Thu, 26 Jul 2001 21:54:37 +0000 (21:54 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 26 Jul 2001 21:54:37 +0000 (21:54 +0000)
d:/whatever instead of /whatever.  While I'm afraid changing isabs()
to be *consistent* with this would break lots of code, it makes
best sense for join() to do it this way.  Thanks to Alex Martelli for
pushing back on this one!

Lib/ntpath.py
Lib/test/test_ntpath.py

index d81e8fb6450aea8d6afe0d08f557574a1487364d..cf7c35366067d9122546a7f88e0500f9a130e816 100644 (file)
@@ -42,11 +42,12 @@ def join(a, *p):
     """Join two or more pathname components, inserting "\\" as needed"""
     path = a
     for b in p:
-        # If path is a raw drive letter (e.g. "C:"), and b doesn't start
-        # with a drive letter, path+b is correct, and regardless of whether
-        # b is absolute on its own.
-        if len(path) == 2 and path[-1] == ":" and splitdrive(b)[0] == "":
-            pass
+        # If path starts with a raw drive letter (e.g. "C:"), and b doesn't
+        # start with a drive letter, path+b is correct, and regardless of\
+        # whether b is absolute on its own.
+        if len(path) >= 2 and path[1] == ":" and splitdrive(b)[0] == "":
+            if path[-1] in "/\\" and b[:1] in "/\\":
+                b = b[1:]
 
         # In any other case, if b is absolute it wipes out the path so far.
         elif isabs(b) or path == "":
index d1b7a0037126c4ed8138186b0e5da62886963be4..7386900ce403f36f79b748281e5a2f3e0d41a99e 100644 (file)
@@ -65,6 +65,7 @@ tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
 tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
 tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
 tester('ntpath.join("a", "b", "\\c")', '\\c')
+tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
 
 if errors:
     raise TestFailed(str(errors) + " errors.")