Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Lib/test/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,12 @@ def _create_underpth_exe(self, lines):
def _calc_sys_path_for_underpth_nosite(self, sys_prefix, lines):
sys_path = []
for line in lines:
if not line or line[0] == '#':
continue
abs_path = os.path.abspath(os.path.join(sys_prefix, line))
if line:
if line[0] == '#':
continue
abs_path = os.path.abspath(os.path.join(sys_prefix, line))
else:
abs_path = ''
sys_path.append(abs_path)
return sys_path

Expand All @@ -535,6 +538,7 @@ def test_underpth_nosite_file(self):
*[libpath for _ in range(200)],
'',
'# comment',
'#import site',
]
exe_file = self._create_underpth_exe(pth_lines)
sys_path = self._calc_sys_path_for_underpth_nosite(
Expand All @@ -545,9 +549,9 @@ def test_underpth_nosite_file(self):
env['PYTHONPATH'] = 'from-env'
env['PATH'] = '{};{}'.format(exe_prefix, os.getenv('PATH'))
output = subprocess.check_output([exe_file, '-c',
'import sys; print("\\n".join(sys.path) if sys.flags.no_site else "")'
'import sys; print(";".join(sys.path) if sys.flags.no_site else "")'
], env=env, encoding='ansi')
actual_sys_path = output.rstrip().split('\n')
actual_sys_path = output.rstrip().split(';')
self.assertTrue(actual_sys_path, "sys.flags.no_site was False")
self.assertEqual(
actual_sys_path,
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ Matt Chisholm
Lita Cho
Sayan Chowdhury
Yuan-Chao Chou
Vladimir Chebotarev
Anders Chrigström
Tom Christiansen
Renee Chu
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue with empty path in sys.path not coming from `_pth`.
27 changes: 15 additions & 12 deletions PC/getpathp.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,15 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path,
if (!p) {
break;
}
if (*p == '\0' || *p == '\r' || *p == '\n' || *p == '#') {
if (*p == '\0' || *p == '#') {
continue;
}
while (*++p) {
while (*p) {
if (*p == '\r' || *p == '\n') {
*p = '\0';
break;
}
++p;
}

if (strcmp(line, "import site") == 0) {
Expand Down Expand Up @@ -615,17 +616,19 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path,
usedsiz += 1;
}

errno_t result;
_Py_BEGIN_SUPPRESS_IPH
result = wcscat_s(buf, bufsiz, prefix);
_Py_END_SUPPRESS_IPH
if (result == EINVAL) {
Py_FatalError("invalid argument during ._pth processing");
} else if (result == ERANGE) {
Py_FatalError("buffer overflow during ._pth processing");
if (line[0] != '\0') {
errno_t result;
_Py_BEGIN_SUPPRESS_IPH
result = wcscat_s(buf, bufsiz, prefix);
_Py_END_SUPPRESS_IPH
if (result == EINVAL) {
Py_FatalError("invalid argument during ._pth processing");
} else if (result == ERANGE) {
Py_FatalError("buffer overflow during ._pth processing");
}
wchar_t *b = &buf[usedsiz];
join(b, wline);
}
wchar_t *b = &buf[usedsiz];
join(b, wline);

PyMem_RawFree(wline);
}
Expand Down