-
Notifications
You must be signed in to change notification settings - Fork 267
Fix MockDirectoryInfo.GetFiles for UNC paths #422
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
Conversation
…xtensions.NormalizeSlashes (TestableIO#421)
|
Thanks, this looks good to me. @rkoeninger, additional pair of eyes? |
|
@fgreinacher Took me a second to see the The change to the first condition should work, but (@DeveloperGuo) the |
|
@DeveloperGuo Instead of // UNC Paths start with double slash but no reason
// to have more than 2 slashes at the start of a path
if (XFS.IsWindowsPlatform() && prefixSeps.Length >= 2)
{
prefixSeps = prefixSeps.Substring(0, 2);
}
else if (prefixSeps.Length > 1)
{
prefixSeps = prefixSeps.Substring(0, 1);
}can we make it something like // UNC Paths start with double slash but no reason
// to have more than 2 slashes at the start of a path
if (XFS.IsWindowsPlatform() && prefixSeps.Length >= 2)
{
prefixSeps = doubleSep;
}
else if (prefixSeps.Length == 1)
{
prefixSeps = sep;
}
else
{
prefixSeps = "";
}I was going to make it a ternary, but a doubly-nested ternary might be a little much. ...I don't know, how about as a ternary, your call: // UNC Paths start with double slash but no reason
// to have more than 2 slashes at the start of a path
prefixSeps =
XFS.IsWindowsPlatform() && prefixSeps.Length >= 2 ? doubleSep :
prefixSeps.Length == 1 ? sep :
""; |
|
@fgreinacher Does that Single-pass slash de-duplicate logic: var builder = new StringBuilder(path.Length);
var prevCh = '\0';
foreach (var ch in path)
{
if (ch != sep || prevCh != sep)
{
builder.Append(ch);
}
prevCh = ch;
}
return prefixSeps + builder.ToString(); |
@rkoeninger - The prefixSep.Length == 0 and 1 cases are already handled by the prefixSeps initialization.
` // UNC Paths start with double slash but no to have more than 2 slashes at the start of a path It may make sense to create separate pull request(s) for the other issue(s) brought up as this one is specifically addressing the regression to UNC paths. |
@DeveloperGuo right, that Your fix should work, so it's fine as is, I just started thinking out loud. |
|
Is this good to go? |
|
👍 Go for it |
|
Thanks @DeveloperGuo! |
- Do not throw exception when calling DirectoryInfoWrapper.Parent for the root directory (#430) by @wexman - Fix MockDirectoryInfo GetFiles for UNC paths caused by bug in StringExtensions.NormalizeSlashes (#422) by @DeveloperGuo - Pass IFileSystem into FileWrapper instead of FileSystem to allow replacement file systems to be used (#432) by @kirbatious - Make sure FileNotFound exceptions contain path and proper message (#427) by @fgreinacher - Do not delete directories that start with the same path (#433) by @updateaman
Regression introduced in v3.0.2 by #418 StringExtensions.NormalizeSlashes.
Unc paths are getting stripped to a single separator.