Eryk Sun <eryk...@gmail.com> added the comment:

The venv launcher can quote the executable path either always or only when it 
contains spaces. The following is a suggestion for implementing the latter.

Before allocating `executable`, use memchr() (include <memory.h>) to search the 
UTF-8 source for a space. If found, increment the character count by two. After 
allocating `executable`, add the initial quote character, and increment the 
pointer.

        BOOL add_quotes = FALSE;
        if (memchr(start, ' ', (size_t)len) != NULL) {
            add_quotes = TRUE;
            cch += 2;
        }

        executable = (wchar_t *)malloc(cch * sizeof(wchar_t));
        if (executable == NULL) {
            error(RC_NO_MEMORY, L"A memory allocation failed");
        }
        
        if (add_quotes) {
            *executable++ = L'\"';
        }

Later, after checking the existence via GetFileAttributesW(), add the trailing 
quote and null, and decrement the pointer:

        if (GetFileAttributesW(executable) == INVALID_FILE_ATTRIBUTES) {
            error(RC_NO_PYTHON, L"No Python at '%ls'", executable);
        }

        if (add_quotes) {
            size_t n = wcslen(executable);
            executable[n] = L'\"';
            executable[n + 1] = L'\0';
            executable--;
        }

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46686>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to