8000 bpo-31904: posixpath.expanduser() handles user home of None by pxinwr · Pull Request #23530 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-31904: posixpath.expanduser() handles user home of None #23530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
* posixpath.expanduser() returns the input path unchanged if
  user home directory is None.
* Skip test_expanduser and test_expanduser_pwd on VxWorks
  • Loading branch information
pxinwr committed Nov 27, 2020
commit 06d9815b83bebbfebc7441892c8a77965c5689d9
3 changes: 3 additions & 0 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ def expanduser(path):
# password database, return the path unchanged
return path
userhome = pwent.pw_dir
# if the current user has no home directory, return the path unchanged
if userhome is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not comfortable to change the behavior on any platform.

I would be ok if the change is specific to VxWorks, if you add:

Suggested change
if userhome is None:
if userhome is None and sys.platform == "vxworks":

Please update the comment and the NEWS entry to mention that only VxWorks is impacted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

return path
if isinstance(path, bytes):
userhome = os.fsencode(userhome)
root = b'/'
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,8 @@ def test_rglob(self):

@unittest.skipUnless(hasattr(pwd, 'getpwall'),
'pwd module does not expose getpwall()')
@unittest.skipIf(sys.platform == "vxworks",
"no home directory on VxWorks")
def test_expanduser(self):
P = self.cls
import_helper.import_module('pwd')
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import posixpath
import sys
import unittest
from posixpath import realpath, abspath, dirname, basename
from test import test_genericpath
Expand Down Expand Up @@ -262,6 +263,8 @@ def test_expanduser_home_envvar(self):
self.assertEqual(posixpath.expanduser("~/"), "/")
self.assertEqual(posixpath.expanduser("~/foo"), "/foo")

@unittest.skipIf(sys.platform == "vxworks",
"no home directory on VxWorks")
def test_expanduser_pwd(self):
pwd = import_helper.import_module('pwd')

Expand Down
0