You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: accept whitespace-only names on Linux and macOS - #1608
On Linux and macOS, MockFileSystem rejected whitespace-only names like " " with ArgumentException: The path is not of a legal form., in FileInfo.New, DirectoryInfo.New, File.WriteAllText, Path.GetFullPath, Path.GetRelativePath and other File methods, and File.Exists always returned false for them. The real file system on Linux and macOS accepts these names.
What was wrong
The mock checks path.Trim() == string.Empty (or string.IsNullOrWhiteSpace) on every platform. In .NET, PathInternal.IsEffectivelyEmpty only treats a whitespace-only path as empty on Windows. On Unix only an empty path is.
What changed
Following the suggestion on the issue to run the check only on Windows, there's a new internal helper, PathVerifier.IsEffectivelyEmpty. An empty path is always effectively empty, and a whitespace-only path is too, but only on Windows. It replaces the whitespace check in the five places that had it:
PathVerifier.IsLegalAbsoluteOrRelative
MockPath.GetFullPath and MockPath.GetRelativePath (for relativeTo)
MockFile.Exists
the MockDirectoryInfo constructor
On Windows the helper does exactly what the old checks did, so nothing changes there. Each call site already handled null before this check, and empty paths are still rejected everywhere.
How it's tested
22 existing tests (32 cases) asserted the Windows rule on every platform: whitespace-only paths in File.Create, Delete, Copy, Move, AppendAllLines, SetAttributes, the Get*Time* methods, File and Directory.CreateSymbolicLink, Path.GetFullPath and GetRelativePath. They now have [WindowsOnly(WindowsSpecifics.StrictPathRules)], like the invalid-character tests next to them. The SetAttributes one also had an "" case, so I moved that into its own test, which still runs everywhere.
New tests (with a new UnixSpecifics.WhitespaceOnlyNames reason):
MockFileInfoTests, Unix only: FileInfo.New(" "), write the file, and find it again through FileInfo.Exists, File.Exists, File.ReadAllText and Directory.GetFiles
MockFileInfoTests, Windows only: FileInfo.New(" ") still throws
MockDirectoryInfoTests, Unix only: DirectoryInfo.New(" ").Create() works and Directory.Exists(" ") is true
MockPathTests, Unix only: GetRelativePath with a whitespace-only relativeTo or path
The Unix tests fail on main and pass with the fix.
I ran this on Linux in the mcr.microsoft.com/dotnet/sdk:11.0.100 container, with the .NET 10, 9 and 8 SDKs added. The Release build of the solution has no warnings or errors. The Wrappers, TestingHelpers and Parity tests all pass on net11.0, net10.0, net9.0 and net8.0, and the API tests pass too. On macOS, the TestingHelpers, Wrappers and Parity tests also pass on net10.0, net9.0 and net8.0 (there is no .NET 11 SDK on that machine).
I couldn't run the Windows tests or net472. On Windows the helper behaves like the old checks, so the existing tests, which now run only there, cover it.
One question I left alone: on Windows, .NET (Core) only treats spaces as empty, so "\u00A0" or "\t" get past Path.GetFullPath there (the issue mentions "\u00A0"), while .NET Framework rejects every kind of whitespace. The mock keeps rejecting all whitespace on Windows, which matches .NET Framework. Should I narrow that to spaces on .NET (Core), or leave it for a separate change?
⚠️ Configuration not compatible with required_status_checks ruleset rule
Details
The ruleset main requires branches to be up to date before merging (strict_required_status_checks_policy). The merge queue tests pull requests in a draft PR built on the latest base branch, then merges the original pull requests. Their own branches were not updated with that base branch, so GitHub considers them out of date and refuses to merge them.
To fix it, turn off Require branches to be up to date before merging in the ruleset main. It is safe to turn off: the merge queue already tests every pull request it merges on the latest base branch, together with the ones queued ahead of it. That is what this setting checks. Changing the setting needs admin access.
If you need to keep the setting:
Add Mergify as a bypass actor on the ruleset main, with exempt mode: the rule stays enforced for everyone else.
Use merge_method: fast-forward: the queue pushes the tested draft PR's branch to the base branch itself, which the setting does not refuse.
Use in-place checks: Mergify tests each pull request on its own branch, one at a time, which gives up parallel checks and batches. To do so, set merge_queue.max_parallel_checks: 1 and merge_queue.mode: serial, set every queue rule batch_size: 1 and max_checks_retries: 0, use a merge_method other than merge-batch, and avoid two-step CI (make merge_conditions identical to queue_conditions).
⚠️ Configuration not compatible with required_status_checks ruleset rule
Details
The ruleset main requires branches to be up to date before merging (strict_required_status_checks_policy). The merge queue tests pull requests in a draft PR built on the latest base branch, then merges the original pull requests. Their own branches were not updated with that base branch, so GitHub considers them out of date and refuses to merge them.
To fix it, turn off Require branches to be up to date before merging in the ruleset main. It is safe to turn off: the merge queue already tests every pull request it merges on the latest base branch, together with the ones queued ahead of it. That is what this setting checks. Changing the setting needs admin access.
If you need to keep the setting:
Add Mergify as a bypass actor on the ruleset main, with exempt mode: the rule stays enforced for everyone else.
Use merge_method: fast-forward: the queue pushes the tested draft PR's branch to the base branch itself, which the setting does not refuse.
Use in-place checks: Mergify tests each pull request on its own branch, one at a time, which gives up parallel checks and batches. To do so, set merge_queue.max_parallel_checks: 1 and merge_queue.mode: serial, set every queue rule batch_size: 1 and max_checks_retries: 0, use a merge_method other than merge-batch, and avoid two-step CI (make merge_conditions identical to queue_conditions).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1070
On Linux and macOS,
MockFileSystemrejected whitespace-only names like" "withArgumentException: The path is not of a legal form., inFileInfo.New,DirectoryInfo.New,File.WriteAllText,Path.GetFullPath,Path.GetRelativePathand otherFilemethods, andFile.Existsalways returnedfalsefor them. The real file system on Linux and macOS accepts these names.What was wrong
The mock checks
path.Trim() == string.Empty(orstring.IsNullOrWhiteSpace) on every platform. In .NET,PathInternal.IsEffectivelyEmptyonly treats a whitespace-only path as empty on Windows. On Unix only an empty path is.What changed
Following the suggestion on the issue to run the check only on Windows, there's a new internal helper,
PathVerifier.IsEffectivelyEmpty. An empty path is always effectively empty, and a whitespace-only path is too, but only on Windows. It replaces the whitespace check in the five places that had it:PathVerifier.IsLegalAbsoluteOrRelativeMockPath.GetFullPathandMockPath.GetRelativePath(forrelativeTo)MockFile.ExistsMockDirectoryInfoconstructorOn Windows the helper does exactly what the old checks did, so nothing changes there. Each call site already handled
nullbefore this check, and empty paths are still rejected everywhere.How it's tested
22 existing tests (32 cases) asserted the Windows rule on every platform: whitespace-only paths in
File.Create,Delete,Copy,Move,AppendAllLines,SetAttributes, theGet*Time*methods,FileandDirectory.CreateSymbolicLink,Path.GetFullPathandGetRelativePath. They now have[WindowsOnly(WindowsSpecifics.StrictPathRules)], like the invalid-character tests next to them. TheSetAttributesone also had an""case, so I moved that into its own test, which still runs everywhere.New tests (with a new
UnixSpecifics.WhitespaceOnlyNamesreason):MockFileInfoTests, Unix only:FileInfo.New(" "), write the file, and find it again throughFileInfo.Exists,File.Exists,File.ReadAllTextandDirectory.GetFilesMockFileInfoTests, Windows only:FileInfo.New(" ")still throwsMockDirectoryInfoTests, Unix only:DirectoryInfo.New(" ").Create()works andDirectory.Exists(" ")istrueMockPathTests, Unix only:GetRelativePathwith a whitespace-onlyrelativeToorpathThe Unix tests fail on
mainand pass with the fix.I ran this on Linux in the
mcr.microsoft.com/dotnet/sdk:11.0.100container, with the .NET 10, 9 and 8 SDKs added. The Release build of the solution has no warnings or errors. The Wrappers, TestingHelpers and Parity tests all pass on net11.0, net10.0, net9.0 and net8.0, and the API tests pass too. On macOS, the TestingHelpers, Wrappers and Parity tests also pass on net10.0, net9.0 and net8.0 (there is no .NET 11 SDK on that machine).I couldn't run the Windows tests or net472. On Windows the helper behaves like the old checks, so the existing tests, which now run only there, cover it.
One question I left alone: on Windows, .NET (Core) only treats spaces as empty, so
"\u00A0"or"\t"get pastPath.GetFullPaththere (the issue mentions"\u00A0"), while .NET Framework rejects every kind of whitespace. The mock keeps rejecting all whitespace on Windows, which matches .NET Framework. Should I narrow that to spaces on .NET (Core), or leave it for a separate change?