From 52df92c45228dcb1a238181d8c8fa70c8fb5e193 Mon Sep 17 00:00:00 2001 From: Jabin <1094679+jabinb@users.noreply.github.com> Date: Sat, 6 Feb 2021 18:45:44 +1100 Subject: [PATCH] fix(core): Fixes SpanReader moving position before read (#468) --- Projects/Server/Buffers/SpanReader.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Projects/Server/Buffers/SpanReader.cs b/Projects/Server/Buffers/SpanReader.cs index 374ebe86a..e8e67b6b4 100644 --- a/Projects/Server/Buffers/SpanReader.cs +++ b/Projects/Server/Buffers/SpanReader.cs @@ -164,8 +164,9 @@ namespace System.Buffers int index = _buffer.Slice(Position, size).IndexOfTerminator(sizeT); + var span = _buffer.Slice(Position, index < 0 ? size : index); Position += isFixedLength || index < 0 ? size : index + sizeT; - return TextEncoding.GetString(_buffer.Slice(Position, index < 0 ? size : index), encoding, safeString); + return TextEncoding.GetString(span, encoding, safeString); } [MethodImpl(MethodImplOptions.AggressiveInlining)]