]> granicus.if.org Git - python/commitdiff
SF bug 478425: Change in os.path.join (ntpath.py)
authorTim Peters <tim.peters@gmail.com>
Mon, 5 Nov 2001 21:25:02 +0000 (21:25 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 5 Nov 2001 21:25:02 +0000 (21:25 +0000)
ntpath.join('a', '') was producing 'a' instead of 'a\\' as in 2.1.
Impossible to guess what was ever *intended*, but since split('a\\')
produces ('a', ''), I think it's best if join('a', '') gives 'a\\' back.

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

index ed8a2ddf4fa0c6f449e2d040674786ed698d6369..21fadd0eb9bdfdaab624c5c67261c468332376ad 100644 (file)
@@ -82,6 +82,12 @@ def join(a, *p):
                     path += b
                 else:
                     path += "\\" + b
+            else:
+                # path is not empty and does not end with a backslash,
+                # but b is empty; since, e.g., split('a/') produces
+                # ('a', ''), it's best if join() adds a backslash in
+                # this case.
+                path += '\\'
 
     return path
 
index 049bbc1c26284a904afe45d06928d2865f529f66..98569f94cc3f496d4425903b6634577b31b55e4a 100644 (file)
@@ -74,6 +74,14 @@ tester("ntpath.join('c:', 'd:/')", 'd:/')
 tester("ntpath.join('c:/', 'd:/')", 'd:/')
 tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
 
+tester("ntpath.join('')", '')
+tester("ntpath.join('', '', '', '', '')", '')
+tester("ntpath.join('a')", 'a')
+tester("ntpath.join('', 'a')", 'a')
+tester("ntpath.join('', '', '', '', 'a')", 'a')
+tester("ntpath.join('a', '')", 'a\\')
+tester("ntpath.join('a', '', '', '', '')", 'a\\')
+
 tester("ntpath.normpath('A//////././//.//B')", r'A\B')
 tester("ntpath.normpath('A/./B')", r'A\B')
 tester("ntpath.normpath('A/foo/../B')", r'A\B')