Skip to content

Commit c8ba403

Browse files
committed
Make MockDirectory_CreateDirectory_ShouldSupportExtendedLengthPaths pass
Fixes #1304
1 parent 87630ba commit c8ba403

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23

34
namespace System.IO.Abstractions.TestingHelpers;
45

@@ -97,6 +98,14 @@ public bool HasIllegalCharacters(string path, bool checkAdditional)
9798

9899
if (checkAdditional)
99100
{
101+
// AdditionalInvalidPathChars includes '?', but this character is allowed in extended-length
102+
// windows path prefixes (`\\?\`). If we're dealing with such a path, check for invalid
103+
// characters after the prefix.
104+
// Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
105+
const string EXTENDED_LENGTH_PATH_PREFIX = @"\\?\";
106+
if (XFS.IsWindowsPlatform() && path.StartsWith(EXTENDED_LENGTH_PATH_PREFIX))
107+
path = path.Substring(EXTENDED_LENGTH_PATH_PREFIX.Length);
108+
100109
return path.IndexOfAny(invalidPathChars.Concat(AdditionalInvalidPathChars).ToArray()) >= 0;
101110
}
102111

@@ -164,4 +173,4 @@ public bool TryNormalizeDriveName(string name, out string result)
164173
result = name;
165174
return true;
166175
}
167-
}
176+
}

0 commit comments

Comments
 (0)