Skip to content

Commit ac9a252

Browse files
Copilotjkotas
andcommitted
Enable EnumerateDirectoryWithTrailingSpacePeriod test on all platforms
- Removed [PlatformSpecific(TestPlatforms.Windows)] attribute - Updated FileSystemEnumerableFactory to use conditional compilation for PathInternal.IsExtended - On Unix, always trim trailing spaces/periods (no extended syntax concept) - On Windows, skip trimming only for paths with \\?\ or \\.\ prefix Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
1 parent 014ce4b commit ac9a252

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,20 @@ internal static bool NormalizeInputs(ref string directory, ref string expression
5151
// "." → "." (relative path reference)
5252
// ".." → ".." (parent directory reference)
5353
// " " → " " (only spaces - would result in empty)
54-
// "\\?\C:\test." → "\\?\C:\test." (extended path syntax - no normalization)
54+
// "\\?\C:\test." → "\\?\C:\test." (extended path syntax on Windows - no normalization)
5555
//
5656
// Algorithm: Trim trailing spaces/periods, but only if:
5757
// 1. Result is non-empty
58-
// 2. Path does not use extended syntax (\\?\ or \\.\)
58+
// 2. On Windows: Path does not use extended syntax (\\?\ or \\.\)
5959

60-
// Don't trim paths using extended syntax (\\?\ or \\.\) as they explicitly disable normalization
61-
if (!PathInternal.IsExtended(directory.AsSpan()))
60+
// Don't trim paths using extended syntax on Windows (\\?\ or \\.\) as they explicitly disable normalization
61+
// On Unix, there's no extended syntax concept, so we always trim (unless result would be empty)
62+
bool shouldTrim = true;
63+
#if WINDOWS
64+
shouldTrim = !PathInternal.IsExtended(directory.AsSpan());
65+
#endif
66+
67+
if (shouldTrim)
6268
{
6369
string trimmed = directory.TrimEnd(' ', '.');
6470

src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Directory/GetFiles.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public void WindowsEnumerateFilesWithTrailingSpacePeriod(string fileName)
223223

224224
[Theory]
225225
[MemberData(nameof(TestData.WindowsTrailingProblematicFileNames), MemberType = typeof(TestData))]
226-
[PlatformSpecific(TestPlatforms.Windows)]
227226
public void EnumerateDirectoryWithTrailingSpacePeriod(string dirName)
228227
{
229228
DirectoryInfo parentDir = Directory.CreateDirectory(GetTestFilePath());

0 commit comments

Comments
 (0)