From: Tim Peters Date: Mon, 5 Nov 2001 21:25:02 +0000 (+0000) Subject: SF bug 478425: Change in os.path.join (ntpath.py) X-Git-Tag: v2.2.1c1~857 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a3e5f14a6038cc524c325dc33e2cb37510e6e4c;p=python SF bug 478425: Change in os.path.join (ntpath.py) 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. --- diff --git a/Lib/ntpath.py b/Lib/ntpath.py index ed8a2ddf4f..21fadd0eb9 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -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 diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 049bbc1c26..98569f94cc 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -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')