diff options
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r-- | Lib/posixpath.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 7e3f3db4b6d..4914a1728ab 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -246,7 +246,12 @@ def expanduser(path): if i == 1: if 'HOME' not in os.environ: import pwd - userhome = pwd.getpwuid(os.getuid()).pw_dir + try: + userhome = pwd.getpwuid(os.getuid()).pw_dir + except KeyError: + # bpo-10496: if the current user identifier doesn't exist in the + # password database, return the path unchanged + return path else: userhome = os.environ['HOME'] else: @@ -257,6 +262,8 @@ def expanduser(path): try: pwent = pwd.getpwnam(name) except KeyError: + # bpo-10496: if the user name from the path doesn't exist in the + # password database, return the path unchanged return path userhome = pwent.pw_dir if isinstance(path, bytes): |