Skip to content

fix: accept whitespace-only names on Linux and macOS - #1608

Merged
mergify[bot] merged 3 commits into
TestableIO:mainfrom
mohsinaliwork686-rgb:fix/whitespace-names-on-unix
Nov 28, 2026
Merged

mergify[bot] merged 3 commits into
TestableIO:mainfrom
mohsinaliwork686-rgb:fix/whitespace-names-on-unix

Conversation

@mohsinaliwork686-rgb

Copy link
Copy Markdown
Contributor

Fixes #1070

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?

@mergify

mergify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@mergify

mergify Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

queue

⚠️ 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).

Learn more in the documentation.

1 similar comment
@mergify

mergify Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

queue

⚠️ 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).

Learn more in the documentation.

@vbreuss vbreuss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: I would move the .NET Framework vs. .NET Core distinction to a separate PR (if necessary).

@mergify
mergify Bot merged commit f7f2475 into TestableIO:main Nov 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PathVerifier fails on whitespace filename under Linux and .NET Core

2 participants