Skip to content

Commit 4ac9001

Browse files
benaadamsdavidfowl
authored andcommitted
Safe utf8 string conversion (#9131)
1 parent fb037bd commit 4ac9001

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/PathNormalizer.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static string DecodePath(Span<byte> path, bool pathEncoded, string rawTar
3535
// https://tools.ietf.org/html/rfc3986#section-2.2
3636
pathLength = RemoveDotSegments(path.Slice(0, pathLength));
3737

38-
return GetUtf8String(path.Slice(0, pathLength));
38+
return Encoding.UTF8.GetString(path.Slice(0, pathLength));
3939
}
4040

4141
pathLength = RemoveDotSegments(path);
@@ -50,16 +50,6 @@ public static string DecodePath(Span<byte> path, bool pathEncoded, string rawTar
5050
return path.Slice(0, pathLength).GetAsciiStringNonNullCharacters();
5151
}
5252

53-
private static unsafe string GetUtf8String(Span<byte> path)
54-
{
55-
// .NET 451 doesn't have pointer overloads for Encoding.GetString so we
56-
// copy to an array
57-
fixed (byte* pointer = path)
58-
{
59-
return Encoding.UTF8.GetString(pointer, path.Length);
60-
}
61-
}
62-
6353
// In-place implementation of the algorithm from https://tools.ietf.org/html/rfc3986#section-5.2.4
6454
public static unsafe int RemoveDotSegments(Span<byte> input)
6555
{

0 commit comments

Comments
 (0)