https://github.com/python/cpython/commit/bc01c5d2252a31304a58c14d0e1aeffa4795092a
commit: bc01c5d2252a31304a58c14d0e1aeffa4795092a
branch: 3.12
author: Steve Dower <[email protected]>
committer: zooba <[email protected]>
date: 2024-05-29T20:12:55+01:00
summary:
gh-119070: Fix py.exe handling of /usr/bin/env commands missing extension
(GH-119426)
files:
A Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst
M Lib/test/test_launcher.py
M PC/launcher2.c
diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py
index 362b507d158288..7dd0b67ea0b3dc 100644
--- a/Lib/test/test_launcher.py
+++ b/Lib/test/test_launcher.py
@@ -717,3 +717,11 @@ def test_literal_shebang_invalid_template(self):
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
index 00000000000000..aab26f57209864
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst
@@ -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``.
diff --git a/PC/launcher2.c b/PC/launcher2.c
index c38cbc83a7ac0f..f331aab3f51e56 100644
--- a/PC/launcher2.c
+++ b/PC/launcher2.c
@@ -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) {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]