Skip to content
Merged
Prev Previous commit
Next Next commit
Make MockDirectory_CreateDirectory_ShouldSupportExtendedLengthPaths pass
Fixes #1304
  • Loading branch information
mostynb committed Jul 4, 2025
commit b9d59a2579bf533ec7099a799f0bf16d91e37238
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;

namespace System.IO.Abstractions.TestingHelpers;

Expand Down Expand Up @@ -97,6 +98,16 @@ public bool HasIllegalCharacters(string path, bool checkAdditional)

if (checkAdditional)
{
// AdditionalInvalidPathChars includes '?', but this character is allowed in extended-length
// windows path prefixes (`\\?\`). If we're dealing with such a path, check for invalid
// characters after the prefix.
// Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
const string EXTENDED_LENGTH_PATH_PREFIX = @"\\?\";
if (XFS.IsWindowsPlatform() && path.StartsWith(EXTENDED_LENGTH_PATH_PREFIX))
{
path = path.Substring(EXTENDED_LENGTH_PATH_PREFIX.Length);
}

return path.IndexOfAny(invalidPathChars.Concat(AdditionalInvalidPathChars).ToArray()) >= 0;
}

Expand Down Expand Up @@ -164,4 +175,4 @@ public bool TryNormalizeDriveName(string name, out string result)
result = name;
return true;
}
}
}