Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PyWinObject_FromEnvironmentBlock behavior #1661

Merged
merged 2 commits into from Mar 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions win32/src/win32profilemodule.cpp
Expand Up @@ -50,11 +50,13 @@ PyObject *PyWinObject_FromEnvironmentBlock(WCHAR *multistring)
return NULL;
totallen = wcslen(multistring);
while (totallen) {
/* Use *last* equal sign as separator, since per-drive working dirs are stored in the environment in the form
"=C:=C:\\somedir","=D:=D:\\someotherdir". These are retrievable by win32api.GetEnvironmentVariable('=C:'),
but don't appear in os.environ and are apparently undocumented
/* Official docs say that the name of an environment variable cannot include an equal sign.
Actually, there are names started with an equal sign, e.g. per-drive working dirs are stored in the form
"=C:=C:\\somedir", "=D:=D:\\someotherdir". These are retrievable by win32api.GetEnvironmentVariable('=C:'),
but don't appear in os.environ. Environment variable's value may contain an equal sign.
So we use the first equal sign from which the string is not started as a separator
*/
eq = wcsrchr(multistring, '=');
eq = wcschr(multistring + 1, '=');
if (eq == NULL) {
// Use blank string for value if no equal sign present. ???? Maybe throw an error instead ????
vallen = 0;
Expand Down