-
Notifications
You must be signed in to change notification settings - Fork 266
Description
Issue
When creating a MockFileSystem with initial files using UNC paths (Windows format) on Unix-like systems, the error handling can be contradictory to the code and inaccurate, as the error message is fixed/hardcoded to Windows paths. For example, when running the below on a Unix-like system
var filesystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{@"\\server\share\file", "content"}
});The error reads System.ArgumentException: The UNC path should be of the form \\server\share. (Parameter 'path'), despite the path being in that exact form, and actually requiring the form //server/share on Unix-like systems.
Cause
It seems there is handling of UNC paths with forward-slash separation following this standard in the MockFileSystem class, from this line:
var isUnc =
StringOperations.StartsWith(fixedPath, @"\\") ||
StringOperations.StartsWith(fixedPath, @"//");The next line uses the platform-specific separator:
lastIndex = StringOperations.IndexOf(fixedPath, separator, 2)Which will then lead to errors if trying to use backslash-separated UNC paths on Unix-like systems, or presumably forwardslash-separated UNC paths on Windows systems (untested). The error message however, as above, is hardcoded/fixed to the Windows paths:
// In MockFileSystem.cs
if (lastIndex < 0)
{
throw CommonExceptions.InvalidUncPath(nameof(path));
}
// In CommonExceptions.cs
public static ArgumentException InvalidUncPath(string paramName) =>
new ArgumentException(@"The UNC path should be of the form \\server\share.", paramName);