Eryk Sun <eryk...@gmail.com> added the comment:
For a "~user" path, the value of userhome should always be used if target_user == current_user. If for some reason the USERPROFILE environment variable isn't defined, the fallback "%HOMEDRIVE%%HOMEPATH%" does not necessarily end in the user's name. Example rewrite: if i != 1: #~user 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) ---------- nosy: +eryksun status: closed -> open _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39899> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com