Skip to content

Commit

Permalink
Fix PyWinObject_FromEnvironmentBlock behavior (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-krikun committed Mar 27, 2021
1 parent 256e043 commit 969c130
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 969c130

Please sign in to comment.