Index: Lib/ntpath.py =================================================================== --- Lib/ntpath.py (revision 85182) +++ Lib/ntpath.py (working copy) @@ -488,8 +488,8 @@ 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) Index: Lib/posixpath.py =================================================================== --- Lib/posixpath.py (revision 85182) +++ Lib/posixpath.py (working copy) @@ -403,8 +403,8 @@ 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])) Index: Lib/test/test_ntpath.py =================================================================== --- Lib/test/test_ntpath.py (revision 85182) +++ Lib/test/test_ntpath.py (working copy) @@ -178,6 +178,16 @@ 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): Index: Lib/test/test_posixpath.py =================================================================== --- Lib/test/test_posixpath.py (revision 85182) +++ Lib/test/test_posixpath.py (working copy) @@ -322,6 +322,15 @@ 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