Skip to content

gh-150880: Normalize Windows scandir wildcard paths#152906

Open
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:fix/scandir-normalize-base-path
Open

gh-150880: Normalize Windows scandir wildcard paths#152906
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:fix/scandir-normalize-base-path

Conversation

@zainnadeem786

@zainnadeem786 zainnadeem786 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

On Windows, os.listdir() and os.scandir() append a wildcard before calling FindFirstFileW().

For paths with a trailing space, this changes the path from a final-component trailing-space case into an internal path component, so Windows no longer trims the space. This makes listdir() and scandir() behave differently from APIs such as open(), os.stat(), and os.path.exists().

This PR normalizes non-extended Windows base paths with GetFullPathNameW() before appending the wildcard used for enumeration.

Extended paths beginning with \\?\ continue to bypass normalization.

Changes

  • Normalize only the wildcard path used by Windows listdir() and scandir().
  • Preserve existing DirEntry.path construction behavior.
  • Preserve extended-path semantics.
  • Add regression coverage for trailing-space directory paths.

Tests

PCbuild\build.bat -p x64 -d
PCbuild\amd64\python_d.exe -m unittest -v test.test_os.test_os.TestScandir.test_windows_trailing_space_path
PCbuild\amd64\python_d.exe -m test test_os
PCbuild\amd64\python_d.exe -m test test_pathlib test_ntpath
git diff --check

Close #150880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On Windows scandir handles paths different from other filesystem APIs

1 participant