Skip to content

Commit 2c35852

Browse files
committed
Attempt to fix the encoder for Windows
1 parent 388dc9d commit 2c35852

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/DotNext/IO/FileUri.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Buffers;
22
using System.Diagnostics;
33
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
45
using System.Text.Encodings.Web;
56

67
namespace DotNext.IO;
@@ -109,10 +110,12 @@ private static bool TryEncodeCore(ReadOnlySpan<char> fileName, UrlEncoder encode
109110
if (index >= 0)
110111
{
111112
component = fileName.Slice(0, index);
112-
fileName = fileName.Slice(index + 1);
113-
replacement = OperatingSystem.IsWindows() && fileName[index] is DriveSeparatorChar
113+
114+
// skip bounds check
115+
replacement = OperatingSystem.IsWindows() && Unsafe.Add(ref MemoryMarshal.GetReference(fileName), index) is DriveSeparatorChar
114116
? escapedDriveSeparatorChar
115117
: slash;
118+
fileName = fileName.Slice(index + 1);
116119
}
117120
else
118121
{

0 commit comments

Comments
 (0)