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

Make network paths be network paths #10191

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,23 @@ private static void NormalizeAndDedupeSlashes(Span<char> span, ref int charsWrit
{
writeSlot = '/';

// if there are two slashes in a row, we skip over one of them, unless we're
// at the start of the span, in order to allow '\\network' paths
if (read > 0 && Unsafe.Add(ref readSlot, 1) is '/' or '\\')
if (Unsafe.Add(ref readSlot, 1) is '/' or '\\')
{
read++;
// We found two slashes in a row. If we are at the start of the path,
// we we are at '\\network' paths, so want to leave them alone. Otherwise
// we skip over one of them to de-dupe
if (read == 0)
{
writeSlot = '\\';
writeSlot = ref Unsafe.Add(ref writeSlot, 1);
writeSlot = '\\';
read++;
write++;
}
else if (read > 0)
{
read++;
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ public void Normalize_Windows_StripsPrecedingSlash()
}

[Fact]
public void Normalize_IgnoresUNCPaths()
public void Normalize_NormalizesPathsWithSlashAtPositionOne()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could probably use Thoery for the tests

{
// Arrange
var path = @"d\ComputerName\path\to\something";

// Act
path = FilePathNormalizer.Normalize(path);

// Assert
Assert.Equal("d/ComputerName/path/to/something", path);
}

[Fact]
public void Normalize_FixesUNCPaths()
{
// Arrange
var path = "//ComputerName/path/to/something";
Expand All @@ -34,7 +47,20 @@ public void Normalize_IgnoresUNCPaths()
path = FilePathNormalizer.Normalize(path);

// Assert
Assert.Equal("//ComputerName/path/to/something", path);
Assert.Equal(@"\\ComputerName/path/to/something", path);
}

[Fact]
public void Normalize_IgnoresUNCPaths()
{
// Arrange
var path = @"\\ComputerName\path\to\something";

// Act
path = FilePathNormalizer.Normalize(path);

// Assert
Assert.Equal(@"\\ComputerName/path/to/something", path);
}

[Fact]
Expand Down