diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2010-10-18 13:55:29 (GMT) |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2010-10-18 13:55:29 (GMT) |
commit | 50f7d7e21346875886d0b86c50ff46adb7049b6b (patch) | |
tree | 2063a0d1532b4b11b60ac36514b9e77b24dc5481 | |
parent | 0491047580e18f06727146fcdfc6b46c83ef537e (diff) | |
download | cpython-50f7d7e21346875886d0b86c50ff46adb7049b6b.zip cpython-50f7d7e21346875886d0b86c50ff46adb7049b6b.tar.gz cpython-50f7d7e21346875886d0b86c50ff46adb7049b6b.tar.bz2 |
Issue #5117: Fixed root directory related issue on posixpath.relpath() and
ntpath.relpath().
-rw-r--r-- | Lib/ntpath.py | 4 | ||||
-rw-r--r-- | Lib/posixpath.py | 4 | ||||
-rw-r--r-- | Lib/test/test_ntpath.py | 10 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 9 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
5 files changed, 26 insertions, 4 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 11a0a3e..091a242 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -488,8 +488,8 @@ def relpath(path, start=curdir): if not path: raise ValueError("no path specified") - start_list = abspath(start).split(sep) - path_list = abspath(path).split(sep) + start_list = [x for x in abspath(start).split(sep) if x] + path_list = [x for x in abspath(path).split(sep) if x] if start_list[0].lower() != path_list[0].lower(): unc_path, rest = splitunc(path) unc_start, rest = splitunc(start) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 81f25b8..aae38d5 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -403,8 +403,8 @@ def relpath(path, start=curdir): if not path: raise ValueError("no path specified") - start_list = abspath(start).split(sep) - path_list = abspath(path).split(sep) + start_list = [x for x in abspath(start).split(sep) if x] + path_list = [x for x in abspath(path).split(sep) if x] # Work out how much of the filepath is shared by start and path. i = len(commonprefix([start_list, path_list])) diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 73645f1..e1852c0 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -178,6 +178,16 @@ class TestNtpath(unittest.TestCase): tester('ntpath.relpath("a", "b/c")', '..\\..\\a') tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a') tester('ntpath.relpath("a", "a")', '.') + tester('ntpath.relpath("/foo/bar/bat", "/x/y/z")', '..\\..\\..\\foo\\bar\\bat') + tester('ntpath.relpath("/foo/bar/bat", "/foo/bar")', 'bat') + tester('ntpath.relpath("/foo/bar/bat", "/")', 'foo\\bar\\bat') + tester('ntpath.relpath("/", "/foo/bar/bat")', '..\\..\\..') + tester('ntpath.relpath("/foo/bar/bat", "/x")', '..\\foo\\bar\\bat') + tester('ntpath.relpath("/x", "/foo/bar/bat")', '..\\..\\..\\x') + tester('ntpath.relpath("/", "/")', '.') + tester('ntpath.relpath("/a", "/a")', '.') + tester('ntpath.relpath("/a/b", "/a/b")', '.') + tester('ntpath.relpath("c:/foo", "C:/FOO")', '.') class NtCommonTest(test_genericpath.CommonTest): diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 2288c48..8bb78d6 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -322,6 +322,15 @@ class PosixPathTest(unittest.TestCase): self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b") self.assertEqual(posixpath.relpath("a", "b/c"), "../../a") self.assertEqual(posixpath.relpath("a", "a"), ".") + self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat') + self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat') + self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat') + self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..') + self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat') + self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x') + self.assertEqual(posixpath.relpath("/", "/"), '.') + self.assertEqual(posixpath.relpath("/a", "/a"), '.') + self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.') finally: os.getcwd = real_getcwd @@ -60,6 +60,9 @@ Core and Builtins Library ------- +- Issue #5117: Fixed root directory related issue on posixpath.relpath() and + ntpath.relpath(). + - Issue 9409: Fix the regex to match all kind of filenames, for interactive debugging in doctests. |