]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-119070: Fix py.exe handling of /usr/bin/env commands missing extension (GH-119426)
authorSteve Dower <steve.dower@python.org>
Wed, 29 May 2024 19:12:55 +0000 (20:12 +0100)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 19:12:55 +0000 (20:12 +0100)
Lib/test/test_launcher.py
Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst [new file with mode: 0644]
PC/launcher2.c

index 362b507d1582889d0d48afb5b927976b7e52a6b7..7dd0b67ea0b3dc3f15630d6b095dafd226bc7012 100644 (file)
@@ -717,3 +717,11 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
             f"{expect} arg1 {script}",
             data["stdout"].strip(),
         )
+
+    def test_shebang_executable_extension(self):
+        with self.script('#! /usr/bin/env python3.12') as script:
+            data = self.run_py([script])
+        expect = "# Search PATH for python3.12.exe"
+        actual = [line.strip() for line in data["stderr"].splitlines()
+                  if line.startswith("# Search PATH")]
+        self.assertEqual([expect], actual)
diff --git a/Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst b/Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst
new file mode 100644 (file)
index 0000000..aab26f5
--- /dev/null
@@ -0,0 +1,3 @@
+Fixes ``py.exe`` handling of shebangs like ``/usr/bin/env python3.12``,
+which were previously interpreted as ``python3.exe`` instead of
+``python3.12.exe``.
index c38cbc83a7ac0fc88c5ecc236c8bbf65b435a65a..f331aab3f51e56ba7582f07810c1a4f7c737b775 100644 (file)
@@ -846,7 +846,7 @@ searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength)
     }
 
     wchar_t filename[MAXLEN];
-    if (wcsncpy_s(filename, MAXLEN, command, lastDot)) {
+    if (wcsncpy_s(filename, MAXLEN, command, commandLength)) {
         return RC_BAD_VIRTUAL_PATH;
     }
 
@@ -858,6 +858,8 @@ searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength)
         }
     }
 
+    debug(L"# Search PATH for %s\n", filename);
+
     wchar_t pathVariable[MAXLEN];
     int n = GetEnvironmentVariableW(L"PATH", pathVariable, MAXLEN);
     if (!n) {