Handle chunks containing multiple EOL (#6146)

Credit to @EEParker a169dd6d39 (diff-6d394759c0a824a137b47986d0cce571R158)

Co-Authored-By: Jeff Parker, PE <eeparker@users.noreply.github.com>
This commit is contained in:
Daniel Gasparotto 2019-07-12 23:27:28 +02:00
parent fb5da88b25
commit 0ae689c8a8
1 changed files with 14 additions and 8 deletions

View File

@ -89,17 +89,23 @@ namespace Microsoft.AspNetCore.NodeServices.Util
OnChunk(new ArraySegment<char>(buf, 0, chunkLength));
var lineBreakPos = Array.IndexOf(buf, '\n', 0, chunkLength);
if (lineBreakPos < 0)
int lineBreakPos = -1;
int startPos = 0;
// get all the newlines
while ((lineBreakPos = Array.IndexOf(buf, '\n', startPos, chunkLength - startPos)) >= 0 && startPos < chunkLength)
{
_linesBuffer.Append(buf, 0, chunkLength);
}
else
{
_linesBuffer.Append(buf, 0, lineBreakPos + 1);
var length = (lineBreakPos + 1) - startPos;
_linesBuffer.Append(buf, startPos, length);
OnCompleteLine(_linesBuffer.ToString());
_linesBuffer.Clear();
_linesBuffer.Append(buf, lineBreakPos + 1, chunkLength - (lineBreakPos + 1));
startPos = lineBreakPos + 1;
}
// get the rest
if (lineBreakPos < 0 && startPos < chunkLength)
{
_linesBuffer.Append(buf, startPos, chunkLength);
}
}
}