Safe utf8 string conversion (#9131)

This commit is contained in:
Ben Adams 2019-04-06 06:12:13 +01:00 committed by David Fowler
parent fb037bda01
commit 4ac9001f6e
1 changed files with 1 additions and 11 deletions

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
// https://tools.ietf.org/html/rfc3986#section-2.2
pathLength = RemoveDotSegments(path.Slice(0, pathLength));
return GetUtf8String(path.Slice(0, pathLength));
return Encoding.UTF8.GetString(path.Slice(0, pathLength));
}
pathLength = RemoveDotSegments(path);
@ -50,16 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
return path.Slice(0, pathLength).GetAsciiStringNonNullCharacters();
}
private static unsafe string GetUtf8String(Span<byte> path)
{
// .NET 451 doesn't have pointer overloads for Encoding.GetString so we
// copy to an array
fixed (byte* pointer = path)
{
return Encoding.UTF8.GetString(pointer, path.Length);
}
}
// In-place implementation of the algorithm from https://tools.ietf.org/html/rfc3986#section-5.2.4
public static unsafe int RemoveDotSegments(Span<byte> input)
{