[Python-checkins] (no subject)
Łukasz Langa
webhook-mailer at python.org
Wed Aug 26 20:24:47 EDT 2020
To: python-checkins at python.org
Subject: bpo-33660: Fix PosixPath to resolve a relative path on root
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
https://github.com/python/cpython/commit/94ad6c674f7687ef22853cb8d42b440d6b42=
ddc8
commit: 94ad6c674f7687ef22853cb8d42b440d6b42ddc8
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: =C5=81ukasz Langa <lukasz at langa.pl>
date: 2020-08-27T02:24:38+02:00
summary:
bpo-33660: Fix PosixPath to resolve a relative path on root
files:
A Misc/NEWS.d/next/Library/2018-06-12-23-30-41.bpo-33660.AdDn5Z.rst
M Lib/pathlib.py
M Lib/test/test_pathlib.py
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 9f5e27b91178e..babc443dd3b30 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -329,7 +329,10 @@ def _resolve(path, rest):
# parent dir
path, _, _ =3D path.rpartition(sep)
continue
- newpath =3D path + sep + name
+ if path.endswith(sep):
+ newpath =3D path + name
+ else:
+ newpath =3D path + sep + name
if newpath in seen:
# Already seen this path
path =3D seen[newpath]
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 04f7c3d86671b..2cb6738a295b6 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -2349,6 +2349,15 @@ def test_open_mode(self):
st =3D os.stat(join('other_new_file'))
self.assertEqual(stat.S_IMODE(st.st_mode), 0o644)
=20
+ def test_resolve_root(self):
+ current_directory =3D os.getcwd()
+ try:
+ os.chdir('/')
+ p =3D self.cls('spam')
+ self.assertEqual(str(p.resolve()), '/spam')
+ finally:
+ os.chdir(current_directory)
+
def test_touch_mode(self):
old_mask =3D 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.rs=
t b/Misc/NEWS.d/next/Library/2018-06-12-23-30-41.bpo-33660.AdDn5Z.rst
new file mode 100644
index 0000000000000..cce3dbb1c6ea5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-12-23-30-41.bpo-33660.AdDn5Z.rst
@@ -0,0 +1,2 @@
+Fix pathlib.PosixPath to resolve a relative path located on the root
+directory properly.
More information about the Python-checkins
mailing list