Skip to content

Commit bc01c5d

Browse files
authored
gh-119070: Fix py.exe handling of /usr/bin/env commands missing extension (GH-119426)
1 parent a62681c commit bc01c5d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/test/test_launcher.py

+8
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,11 @@ def test_literal_shebang_invalid_template(self):
717717
f"{expect} arg1 {script}",
718718
data["stdout"].strip(),
719719
)
720+
721+
def test_shebang_executable_extension(self):
722+
with self.script('#! /usr/bin/env python3.12') as script:
723+
data = self.run_py([script])
724+
expect = "# Search PATH for python3.12.exe"
725+
actual = [line.strip() for line in data["stderr"].splitlines()
726+
if line.startswith("# Search PATH")]
727+
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

+3-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength)
846846
}
847847

848848
wchar_t filename[MAXLEN];
849-
if (wcsncpy_s(filename, MAXLEN, command, lastDot)) {
849+
if (wcsncpy_s(filename, MAXLEN, command, commandLength)) {
850850
return RC_BAD_VIRTUAL_PATH;
851851
}
852852

@@ -858,6 +858,8 @@ searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength)
858858
}
859859
}
860860

861+
debug(L"# Search PATH for %s\n", filename);
862+
861863
wchar_t pathVariable[MAXLEN];
862864
int n = GetEnvironmentVariableW(L"PATH", pathVariable, MAXLEN);
863865
if (!n) {

0 commit comments

Comments
 (0)