Skip to content

Commit 2590ae8

Browse files
committed
Fixed slash prefix for local path on Windows
1 parent 3998616 commit 2590ae8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/DotNext/IO/FileUri.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public static class FileUri
1818
// \\?\folder => file://?/folder
1919
// \\.\folder => file://./folder
2020
private const string FileScheme = "file://";
21-
private const string UncPrefix = @"\\";
2221

2322
/// <summary>
2423
/// Encodes file name as URI.
@@ -91,12 +90,13 @@ private static bool TryEncodeCore(ReadOnlySpan<char> fileName, UrlEncoder encode
9190
{
9291
// nothing to do
9392
}
94-
else if (fileName.StartsWith(UncPrefix))
93+
else if (fileName is ['\\', '\\', .. var rest]) // UNC path
9594
{
96-
fileName = fileName.Slice(UncPrefix.Length);
95+
fileName = rest;
9796
}
9897
else if (GetPathComponent(ref fileName, out endsWithTrailingSeparator) is [.. var drive, driveSeparator])
9998
{
99+
writer.Add(slash);
100100
writer.Write(drive);
101101
writer.Write(endsWithTrailingSeparator ? [escapedDriveSeparatorChar, slash] : [escapedDriveSeparatorChar]);
102102
}

0 commit comments

Comments
 (0)