-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Windows] Fix Directory.GetFiles() returning paths with trailing spaces or periods when directory has trailing spaces or periods #121038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
654d046
5e3bf96
2a5b37c
e56dc76
63f7b83
908c56c
a9c933b
f8ffe2a
5457f04
e652606
9857edb
5e3dbba
dc2eeea
2bf80fc
e66a19e
89b835a
014ce4b
ac9a252
5eb1705
4e02f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,15 +224,14 @@ public void WindowsEnumerateFilesWithTrailingSpacePeriod(string fileName) | |
| [Theory] | ||
| [MemberData(nameof(TestData.WindowsTrailingProblematicFileNames), MemberType = typeof(TestData))] | ||
| [PlatformSpecific(TestPlatforms.Windows)] | ||
jkotas marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot This test does not seem to testing Windows specific behavior. Please enable the test on all platforms and make sure that it passed on all platforms There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enabled on all platforms. Updated FileSystemEnumerableFactory to use conditional compilation ( |
||
| [ActiveIssue("https://github.com/dotnet/runtime/issues/113120")] | ||
| public void WindowsEnumerateDirectoryWithTrailingSpacePeriod(string dirName) | ||
jkotas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
jkotas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| DirectoryInfo parentDir = Directory.CreateDirectory(GetTestFilePath()); | ||
| string problematicDirPath = Path.Combine(parentDir.FullName, dirName); | ||
| Directory.CreateDirectory(@"\\?\" + problematicDirPath); | ||
| Directory.CreateDirectory(problematicDirPath); | ||
|
|
||
| string normalFileName = "normalfile.txt"; | ||
| string filePath = Path.Combine(problematicDirPath, normalFileName); | ||
| string filePath = Path.Combine(Path.GetFullPath(problematicDirPath), normalFileName); | ||
| File.Create(filePath).Dispose(); | ||
|
|
||
| string[] files = GetEntries(problematicDirPath); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkotas, this will change behavior for FileSystemEntry.OriginalRootDirectory. Should we change it instead at the level of FileSystemEnumerable consumers?
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs
Lines 114 to 206 in 97669b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can instead just trim whitespace if there's no
\\?\prefix instead of Path.GetFullPath.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, it does not help that we have exactly zero tests for this property.
@copilot Could you please address @jozkee's feedback? Also, add a test for OriginalRootDirectory property that would have caught this regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed @jozkee's feedback. Moved the fix to
FileSystemEnumerableFactory.NormalizeInputs()to trim trailing spaces, preservingOriginalRootDirectoryAPI behavior. Added tests forOriginalRootDirectoryproperty that verify it preserves both trailing separators and trailing spaces (as it did before the change).The fix now only affects
Directory.*APIs throughNormalizeInputs, not directFileSystemEnumeratorusage. Commit: 5457f04