Merge pull request #12137 from dgaspar/master

Handle chunks containing multiple EOL (#6146)
This commit is contained in:
Ryan Brandenburg 2019-08-28 11:50:29 -07:00 committed by GitHub
commit ab02951b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
}
}