Skip to content
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

PathVerifier fails on whitespace filename under Linux and .NET Core #1070

Open
AnakinRaW opened this issue Dec 25, 2023 · 1 comment
Open
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality

Comments

@AnakinRaW
Copy link

AnakinRaW commented Dec 25, 2023

Describe the bug
When using FileSystem and MockFileSystem I noticed there is different behavior when creating a new IFileInfo using only whitespaces.
The "error" trails down to the PathVerifier that the MockFileSystem uses

To Reproduce

// Both throw in Linux and windows
var mfs = new MockFileSystem();
mfs.FileInfo.New("   "); // ASCII space
mfs.FileInfo.New("\u00A0"); // Unicode char that's treated as whitespace

// Both pass in Linux
mfs.FileInfo.New("./   ") // Explicit relative path 
mfs.FileInfo.New("/   ") // Explicit absolute path 

// Passes in Linux 
var fs = new FileSystem();
fs.FileInfo.New("   "); // ASCII space

// Passes in Linux and Windows (.NET Core); throws on NET4.8
fs.FileInfo.New("\u00A0"); // Unicode char that's treated as whitespace

Expected behavior
Both calls throw an exception when they should not.
For Linux (whitespace) is a valid file name
For Windows and Linux \u00A0 is a valid file name. However under .NET Framework it also fails

Additional context
In PathInternal.OS.cs .NET has a bool IsEffectivelyEmpty(string? path) method which behaves differently to linux and windows, just to cover those cases.

Currently PathVerifier uses the string.Trim() method, which causes the two explained scenarios

  • valid unicode chars get trimmed (\u00A0)
  • a whitespace-only relative path is considered to be illegal when it actually is not under linux.
@AnakinRaW AnakinRaW added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Dec 25, 2023
vbreuss added a commit to Testably/Testably.Abstractions that referenced this issue Dec 31, 2023
As reported in
TestableIO/System.IO.Abstractions#1070,
whitespace-only files are treated differently depending on the
underlying operating system:
- Windows only supports unicode-whitespace, but throws on filenames with
only blanks
- Linux supports both files with only blanks or with unicode-whitespace
@fgreinacher fgreinacher added state: ready to pick Issues that are ready for being worked on area: testinghelpers Issues that address the testing helpers and removed state: needs discussion Issues that need further discussion labels Jan 9, 2024
@fgreinacher
Copy link
Contributor

Thanks for reporting! Happy to accept a PR to fix this 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

2 participants