Skip to content

Commit ba1db57

Browse files
authored
bpo-39899: Don't double-check directory name if we're requesting the current user's home directory in ntpath.expanduser() (GH-25277)
1 parent 11c3bd3 commit ba1db57

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Lib/ntpath.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,19 @@ def expanduser(path):
313313
userhome = join(drive, os.environ['HOMEPATH'])
314314

315315
if i != 1: #~user
316-
# Try to guess user home directory. By default all users directories
317-
# are located in the same place and are named by corresponding
318-
# usernames. If current user home directory points to nonstandard
319-
# place, this guess is likely wrong, and so we bail out.
320-
current_user = os.environ.get('USERNAME')
321-
if current_user != basename(userhome):
322-
return path
323-
324316
target_user = path[1:i]
325317
if isinstance(target_user, bytes):
326318
target_user = os.fsdecode(target_user)
319+
current_user = os.environ.get('USERNAME')
320+
327321
if target_user != current_user:
322+
# Try to guess user home directory. By default all user
323+
# profile directories are located in the same place and are
324+
# named by corresponding usernames. If userhome isn't a
325+
# normal profile directory, this guess is likely wrong,
326+
# so we bail out.
327+
if current_user != basename(userhome):
328+
return path
328329
userhome = join(dirname(userhome), target_user)
329330

330331
if isinstance(path, bytes):

0 commit comments

Comments
 (0)