Message390038
getenvironment() in Modules/_winapi.c needs to sort variables in the environment block and remove duplicates case insensitively [1].
The sort order used to matter with SetEnvironmentVairableW(). As soon as it reached a name in the environment block that compared greater than the target name, it would insert a new variable. Nowadays, SetEnvironmentVairableW() searches the entire environment block before inserting a new value. Regardless, at the very least, getenvironment() is not well-behaved and not setting the environment in the documented sort order that users, and possibly other programs, expect.
Case-insensitive sorting in Windows uses upper case. The variable names in the mapping can be added to a list and sorted with a key function that's based on LCMapStringEx() [2], with the flag LCMAP_UPPERCASE. Loop over the sorted list to create the environment block. Remove duplicates by skipping a name that compares equal to the previously stored name according to CompareStringOrdinal() [3].
_winapi.LCMapStringEx(src, flags=LCMAP_UPPERCASE, locale=LOCALE_NAME_INVARIANT) could also be used in ntpath.normcase(), which would resolve bpo-42658.
---
[1] https://docs.microsoft.com/en-us/windows/win32/procthread/changing-environment-variables
[2] https://docs.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-lcmapstringex
[3] https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal |
|
Date |
User |
Action |
Args |
2021-04-02 04:16:14 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower |
2021-04-02 04:16:14 | eryksun | set | messageid: <1617336974.49.0.41114511179.issue43702@roundup.psfhosted.org> |
2021-04-02 04:16:14 | eryksun | link | issue43702 messages |
2021-04-02 04:16:14 | eryksun | create | |
|