@@ -1926,27 +1926,35 @@ process(int argc, wchar_t ** argv)
1926
1926
if (!cch ) {
1927
1927
error (0 , L"Cannot determine memory for home path" );
1928
1928
}
1929
- cch += (DWORD )wcslen (PYTHON_EXECUTABLE ) + 1 + 1 ; /* include sep and null */
1929
+ cch += (DWORD )wcslen (PYTHON_EXECUTABLE ) + 4 ; /* include sep, null and quotes */
1930
1930
executable = (wchar_t * )malloc (cch * sizeof (wchar_t ));
1931
1931
if (executable == NULL ) {
1932
1932
error (RC_NO_MEMORY , L"A memory allocation failed" );
1933
1933
}
1934
- cch_actual = MultiByteToWideChar (CP_UTF8 , 0 , start , len , executable , cch );
1934
+ /* start with a quote - we'll skip this ahead, but want it for the final string */
1935
+ executable [0 ] = L'"' ;
1936
+ cch_actual = MultiByteToWideChar (CP_UTF8 , 0 , start , len , & executable [1 ], cch - 1 );
1935
1937
if (!cch_actual ) {
1936
1938
error (RC_BAD_VENV_CFG , L"Cannot decode home path in '%ls'" ,
1937
1939
venv_cfg_path );
1938
1940
}
1941
+ cch_actual += 1 ; /* account for the first quote */
1942
+ executable [cch_actual ] = L'\0' ;
1939
1943
if (executable [cch_actual - 1 ] != L'\\' ) {
1940
1944
executable [cch_actual ++ ] = L'\\' ;
1941
1945
executable [cch_actual ] = L'\0' ;
1942
1946
}
1943
- if (wcscat_s (executable , cch , PYTHON_EXECUTABLE )) {
1947
+ if (wcscat_s (& executable [ 1 ] , cch - 1 , PYTHON_EXECUTABLE )) {
1944
1948
error (RC_BAD_VENV_CFG , L"Cannot create executable path from '%ls'" ,
1945
1949
venv_cfg_path );
1946
1950
}
1947
- if (GetFileAttributesW (executable ) == INVALID_FILE_ATTRIBUTES ) {
1951
+ /* there's no trailing quote, so we only have to skip one character for the test */
1952
+ if (GetFileAttributesW (& executable [1 ]) == INVALID_FILE_ATTRIBUTES ) {
1948
1953
error (RC_NO_PYTHON , L"No Python at '%ls'" , executable );
1949
1954
}
1955
+ /* now append the final quote */
1956
+ wcscat_s (executable , cch , L"\"" );
1957
+ /* smuggle our original path through */
1950
1958
if (!SetEnvironmentVariableW (L"__PYVENV_LAUNCHER__" , argv0 )) {
1951
1959
error (0 , L"Failed to set launcher environment" );
1952
1960
}
0 commit comments