]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33660: Fix PosixPath to resolve a relative path on root
authorDong-hee Na <donghee.na92@gmail.com>
Tue, 12 Jun 2018 14:30:45 +0000 (23:30 +0900)
committerŁukasz Langa <lukasz@langa.pl>
Thu, 27 Aug 2020 00:24:38 +0000 (02:24 +0200)
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2018-06-12-23-30-41.bpo-33660.AdDn5Z.rst [new file with mode: 0644]

index 9f5e27b91178e68e5e39ab4d3bde8549b5703a73..babc443dd3b30435817b23d49e65707f5b05f290 100644 (file)
@@ -329,7 +329,10 @@ class _PosixFlavour(_Flavour):
                     # parent dir
                     path, _, _ = path.rpartition(sep)
                     continue
-                newpath = path + sep + name
+                if path.endswith(sep):
+                    newpath = path + name
+                else:
+                    newpath = path + sep + name
                 if newpath in seen:
                     # Already seen this path
                     path = seen[newpath]
index 04f7c3d86671bfa48533950e4cfc1f9e37ded325..2cb6738a295b649203d44281cae944fbd13965b4 100644 (file)
@@ -2349,6 +2349,15 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
         st = os.stat(join('other_new_file'))
         self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
 
+    def test_resolve_root(self):
+        current_directory = os.getcwd()
+        try:
+            os.chdir('/')
+            p = self.cls('spam')
+            self.assertEqual(str(p.resolve()), '/spam')
+        finally:
+            os.chdir(current_directory)
+
     def test_touch_mode(self):
         old_mask = os.umask(0)
         self.addCleanup(os.umask, old_mask)
diff --git a/Misc/NEWS.d/next/Library/2018-06-12-23-30-41.bpo-33660.AdDn5Z.rst b/Misc/NEWS.d/next/Library/2018-06-12-23-30-41.bpo-33660.AdDn5Z.rst
new file mode 100644 (file)
index 0000000..cce3dbb
--- /dev/null
@@ -0,0 +1,2 @@
+Fix pathlib.PosixPath to resolve a relative path located on the root
+directory properly.