summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index f5c2260..bbc2369 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -259,7 +259,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:
@@ -267,6 +272,8 @@ def expanduser(path):
try:
pwent = pwd.getpwnam(path[1:i])
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
userhome = userhome.rstrip('/')