This is very frustrating when trying to compare paths, and, sometimes different tools in the same development environments will run in such a way that they change their drive letter case, leading to issues between those tools or differences inside tests.
I would like to suggest that we enforce the lowercase driver letters by making a small change to
result = GetFullPathNameW(path, result, woutbufp, NULL);
if (!result) {
PyMem_RawFree(woutbufp);
return -1;
}
}
if (woutbufp != woutbuf) {
*abspath_p = woutbufp;
return0;
}
*abspath_p = _PyMem_RawWcsdup(woutbufp);
return0;
}
If we were to include an iteration (line 4266) of the buffered path that lowercased the chars up to the colon (guaranteed to be set), this would ensure consistent drive letters.
Your environment
Python 3.9.6
Microsoft Windows 10 Pro - 10.0.19044 Build 19044
x64-based PC
The text was updated successfully, but these errors were encountered:
NTFS on Windows 10+ supports flagging a directory as case sensitive, which makes pure path comparisons unreliable. If that isn't a concern, then we can simply normalize the case of the entire path. Otherwise, we can at least split off the drive via os.path.splitdrive() and normalize the case of the drive component.
It's best to use os.path.normcase() because it uses Windows filesystem rules. It's based on a table that maps one 16-bit ordinal to another 16-bit ordinal. No case conversion is supported for characters beyond the BMP, i.e. UTF-16 surrogate codes map to themselves. There's no linguistic or locale-dependent casing rules (e.g. "ß" <-> "SS") and no Unicode normalization.
eryksun
changed the title
Inconsistent driver letter case on Windows + suggested fix
Inconsistent drive letter case on Windows
Dec 18, 2022
Kieran-Bacon commentedDec 17, 2022
Bug report + suggested fix
The
os.path.abspath
method on windows is inconsistent when pre-pending the drive letter as it can be either upper or lowercase.It is not entirely clear from Microsoft's documentation (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew) when this happens exactly, but, a simple way of re-producing the issue is by changing directory and specifying the opposite case letter in the call
This is very frustrating when trying to compare paths, and, sometimes different tools in the same development environments will run in such a way that they change their drive letter case, leading to issues between those tools or differences inside tests.
I would like to suggest that we enforce the lowercase driver letters by making a small change to
cpython/Modules/posixmodule.c
Lines 4236 to 4274 in 0fe61d0
If we were to include an iteration (line 4266) of the buffered path that lowercased the chars up to the colon (guaranteed to be set), this would ensure consistent drive letters.
Your environment
Python 3.9.6
Microsoft Windows 10 Pro - 10.0.19044 Build 19044
x64-based PC
The text was updated successfully, but these errors were encountered: