Python has to append \\* to the path before calling FindFirstFileW. This slightly changes how paths are parsed by the OS.
I think our policy of "as close to the OS behaviour as is portable" still applies here, but because we're the ones appending
\\*to the path forscandir, trimming spaces first isn't unreasonable. I'd rather use an API that doesn't involve us modifying the path, but if that doesn't exist, then we don't have a lot of choice.But since the original issue was opened for "what's the general policy on this" and that's been answered, let's start a new issue specifically for
scandir.
Originally posted by @zooba in #115104
To fix this, GetFullPathNameW could be used before appending \\* to the path and calling FindFirstFileW. This will create a normalized absolute path without changing the meaning of the path (as far as the OS is concerned). So it'll be consistent with other filesystem APIs.
Linked PRs
- gh-150880: Normalize Windows scandir wildcard paths #152906
- [3.15] gh-150880: Normalize paths on Windows before appending wildcard (GH-152906) #152963
- [3.14] gh-150880: Normalize paths on Windows before appending wildcard (GH-152906) #152964
- [3.13] gh-150880: Normalize paths on Windows before appending wildcard (GH-152906) #152965
- gh-150880: Clarify DirEntry.path construction semantics #153218
- [3.15] gh-150880: Clarify DirEntry.path construction semantics (GH-153218) #153219
- [3.14] gh-150880: Clarify DirEntry.path construction semantics (GH-153218) #153220
- [3.13] gh-150880: Clarify DirEntry.path construction semantics (GH-153218) #153221