This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, hokiedsp, paul.moore, steve.dower, tim.golden, zach.ware
Date 2022-02-09.06:28:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644388134.4.0.337532353418.issue46686@roundup.psfhosted.org>
In-reply-to
Content
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--;
        }
History
Date User Action Args
2022-02-09 06:28:54eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, hokiedsp
2022-02-09 06:28:54eryksunsetmessageid: <1644388134.4.0.337532353418.issue46686@roundup.psfhosted.org>
2022-02-09 06:28:54eryksunlinkissue46686 messages
2022-02-09 06:28:53eryksuncreate