Content-Length: 283424 | pFad | http://github.com/python/cpython/commit/b040617195ff7bfd09acf9cac14177d360aa382f

D5 gh-94772: Fix off-by-one error in Windows launcher (GH-94779) · python/cpython@b040617 · GitHub
Skip to content

Commit

Permalink
gh-94772: Fix off-by-one error in Windows launcher (GH-94779)
Browse files Browse the repository at this point in the history
(cherry picked from commit 407ff65)

Co-authored-by: Paul Moore <p.f.moore@gmail.com>

Co-authored-by: Paul Moore <p.f.moore@gmail.com>
  • Loading branch information
miss-islington and pfmoore authored Jul 16, 2022
1 parent 734c8b7 commit b040617
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Lib/test/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,30 @@ def test_py3_shebang(self):
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())

def test_py_shebang_nl(self):
with self.py_ini(TEST_PY_COMMANDS):
with self.script("#! /usr/bin/env python -prearg\n") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100", data["SearchInfo.tag"])
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())

def test_py2_shebang_nl(self):
with self.py_ini(TEST_PY_COMMANDS):
with self.script("#! /usr/bin/env python2 -prearg\n") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100-32", data["SearchInfo.tag"])
self.assertEqual(f"X.Y-32.exe -prearg {script} -postarg", data["stdout"].strip())

def test_py3_shebang_nl(self):
with self.py_ini(TEST_PY_COMMANDS):
with self.script("#! /usr/bin/env python3 -prearg\n") as script:
data = self.run_py([script, "-postarg"])
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())

def test_install(self):
data = self.run_py(["-V:3.10"], env={"PYLAUNCHER_ALWAYS_INSTALL": "1"}, expect_returncode=111)
cmd = data["stdout"].strip()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incorrect handling of shebang lines in py.exe launcher
4 changes: 3 additions & 1 deletion PC/launcher2.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,9 @@ checkShebang(SearchInfo *search)
while (--bytesRead > 0 && *++b != '\r' && *b != '\n') { }
wchar_t *shebang;
int shebangLength;
int exitCode = _decodeShebang(search, start, (int)(b - start + 1), onlyUtf8, &shebang, &shebangLength);
// We add 1 when bytesRead==0, as in that case we hit EOF and b points
// to the last character in the file, not the newline
int exitCode = _decodeShebang(search, start, (int)(b - start + (bytesRead == 0)), onlyUtf8, &shebang, &shebangLength);
if (exitCode) {
return exitCode;
}
Expand Down

0 comments on commit b040617

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/commit/b040617195ff7bfd09acf9cac14177d360aa382f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy