summaryrefslogtreecommitdiffstats
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2021-04-09 21:28:15 (GMT)
committerGitHub <noreply@github.com>2021-04-09 21:28:15 (GMT)
commitba1db571987c65672d9c06789e9852313ed2412a (patch)
tree5c2a58edced887aa30856636003448d7af325720 /Lib/ntpath.py
parent11c3bd3f6d06649484b81a659c7bf02d6632e607 (diff)
downloadcpython-ba1db571987c65672d9c06789e9852313ed2412a.zip
cpython-ba1db571987c65672d9c06789e9852313ed2412a.tar.gz
cpython-ba1db571987c65672d9c06789e9852313ed2412a.tar.bz2
bpo-39899: Don't double-check directory name if we're requesting the current user's home directory in ntpath.expanduser() (GH-25277)
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 421db50..5ae8079 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -313,18 +313,19 @@ def expanduser(path):
userhome = join(drive, os.environ['HOMEPATH'])
if i != 1: #~user
- # Try to guess user home directory. By default all users directories
- # are located in the same place and are named by corresponding
- # usernames. If current user home directory points to nonstandard
- # place, this guess is likely wrong, and so we bail out.
- current_user = os.environ.get('USERNAME')
- if current_user != basename(userhome):
- return path
-
target_user = path[1:i]
if isinstance(target_user, bytes):
target_user = os.fsdecode(target_user)
+ current_user = os.environ.get('USERNAME')
+
if target_user != current_user:
+ # Try to guess user home directory. By default all user
+ # profile directories are located in the same place and are
+ # named by corresponding usernames. If userhome isn't a
+ # normal profile directory, this guess is likely wrong,
+ # so we bail out.
+ if current_user != basename(userhome):
+ return path
userhome = join(dirname(userhome), target_user)
if isinstance(path, bytes):