Skip to content

Commit c3cfc04

Browse files
gh-119070: Fix py.exe handling of /usr/bin/env commands missing extension (GH-119426)
(cherry picked from commit df93f5d) Co-authored-by: Steve Dower <[email protected]>
1 parent dcfbd3b commit c3cfc04

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/test/test_launcher.py

+8
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,11 @@ def test_shebang_command_in_venv(self):
764764
with self.script(f'#! /usr/bin/env {exe.stem} arg1') as script:
765765
data = self.run_py([script], env=env)
766766
self.assertEqual(data["stdout"].strip(), f"{quote(exe)} arg1 {quote(script)}")
767+
768+
def test_shebang_executable_extension(self):
769+
with self.script('#! /usr/bin/env python3.12') as script:
770+
data = self.run_py([script])
771+
expect = "# Search PATH for python3.12.exe"
772+
actual = [line.strip() for line in data["stderr"].splitlines()
773+
if line.startswith("# Search PATH")]
774+
self.assertEqual([expect], actual)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes ``py.exe`` handling of shebangs like ``/usr/bin/env python3.12``,
2+
which were previously interpreted as ``python3.exe`` instead of
3+
``python3.12.exe``.

PC/launcher2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength)
853853
}
854854

855855
wchar_t filename[MAXLEN];
856-
if (wcsncpy_s(filename, MAXLEN, command, lastDot)) {
856+
if (wcsncpy_s(filename, MAXLEN, command, commandLength)) {
857857
return RC_BAD_VIRTUAL_PATH;
858858
}
859859

0 commit comments

Comments
 (0)