]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36264: Don't honor POSIX HOME in os.path.expanduser on Windows (GH-12282)
authorAnthony Sottile <asottile@umich.edu>
Tue, 12 Mar 2019 15:39:57 +0000 (08:39 -0700)
committerSteve Dower <steve.dower@microsoft.com>
Tue, 12 Mar 2019 15:39:57 +0000 (08:39 -0700)
Lib/distutils/tests/test_config.py
Lib/distutils/tests/test_dist.py
Lib/ntpath.py
Lib/test/test_netrc.py
Lib/test/test_ntpath.py
Misc/NEWS.d/next/Windows/2019-03-11-09-33-47.bpo-36264.rTzWce.rst [new file with mode: 0644]

index 77ef788e247293e0d8e581af78d63dfebe07ba57..344084afb77912dec8cc5a2076bae2eceeab96d4 100644 (file)
@@ -60,6 +60,7 @@ class BasePyPIRCCommandTestCase(support.TempdirManager,
         super(BasePyPIRCCommandTestCase, self).setUp()
         self.tmp_dir = self.mkdtemp()
         os.environ['HOME'] = self.tmp_dir
+        os.environ['USERPROFILE'] = self.tmp_dir
         self.rc = os.path.join(self.tmp_dir, '.pypirc')
         self.dist = Distribution()
 
index 0a19f0fb6274cb67f8cbbb567ed4531206fd8ece..cc34725a99efa423db4a5ab38507b66adcac143b 100644 (file)
@@ -463,7 +463,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
             # win32-style
             if sys.platform == 'win32':
                 # home drive should be found
-                os.environ['HOME'] = temp_dir
+                os.environ['USERPROFILE'] = temp_dir
                 files = dist.find_config_files()
                 self.assertIn(user_filename, files,
                               '%r not found in %r' % (user_filename, files))
index 11bb297e16bf4e04b395fa95177c2091c79780df..b5e1d121fc574e9d0be33b5764e6087000caf540 100644 (file)
@@ -299,9 +299,7 @@ def expanduser(path):
     while i < n and path[i] not in _get_bothseps(path):
         i += 1
 
-    if 'HOME' in os.environ:
-        userhome = os.environ['HOME']
-    elif 'USERPROFILE' in os.environ:
+    if 'USERPROFILE' in os.environ:
         userhome = os.environ['USERPROFILE']
     elif not 'HOMEPATH' in os.environ:
         return path
index ae53988c45a6e352b0f690736b3f1a9d8e04e841..7ce7e565704f74e45c42c3ac2a7b333aaf2fdf27 100644 (file)
@@ -154,6 +154,7 @@ class NetrcTestCase(unittest.TestCase):
             called.append(s)
             with support.EnvironmentVarGuard() as environ:
                 environ.set('HOME', fake_home)
+                environ.set('USERPROFILE', fake_home)
                 result = orig_expanduser(s)
                 return result
 
index 223e50f12c6d56839b51d0b9e3297942fca3832f..fc2398c2d518ba19ab734278842b95377b9f1377 100644 (file)
@@ -262,20 +262,21 @@ class TestNtpath(unittest.TestCase):
             env['USERPROFILE'] = 'C:\\eric\\idle'
             tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
             tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
-
-            env.clear()
-            env['HOME'] = 'C:\\idle\\eric'
-            tester('ntpath.expanduser("~test")', 'C:\\idle\\test')
-            tester('ntpath.expanduser("~")', 'C:\\idle\\eric')
-
             tester('ntpath.expanduser("~test\\foo\\bar")',
-                   'C:\\idle\\test\\foo\\bar')
+                   'C:\\eric\\test\\foo\\bar')
             tester('ntpath.expanduser("~test/foo/bar")',
-                   'C:\\idle\\test/foo/bar')
+                   'C:\\eric\\test/foo/bar')
             tester('ntpath.expanduser("~\\foo\\bar")',
-                   'C:\\idle\\eric\\foo\\bar')
+                   'C:\\eric\\idle\\foo\\bar')
             tester('ntpath.expanduser("~/foo/bar")',
-                   'C:\\idle\\eric/foo/bar')
+                   'C:\\eric\\idle/foo/bar')
+
+            # bpo-36264: ignore `HOME` when set on windows
+            env.clear()
+            env['HOME'] = 'F:\\'
+            env['USERPROFILE'] = 'C:\\eric\\idle'
+            tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
+            tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
 
     @unittest.skipUnless(nt, "abspath requires 'nt' module")
     def test_abspath(self):
diff --git a/Misc/NEWS.d/next/Windows/2019-03-11-09-33-47.bpo-36264.rTzWce.rst b/Misc/NEWS.d/next/Windows/2019-03-11-09-33-47.bpo-36264.rTzWce.rst
new file mode 100644 (file)
index 0000000..aae5986
--- /dev/null
@@ -0,0 +1,2 @@
+Don't honor POSIX ``HOME`` in ``os.path.expanduser`` on windows.  Patch by
+Anthony Sottile.