Tolerate any white-space bytes after the stream operator.

This commit is contained in:
InusualZ
2021-06-13 14:43:06 -04:00
committed by Wesley Moret
parent b3a361e2f2
commit 31ca3640d2

View File

@@ -256,35 +256,20 @@
// Verify again that we start with "stream" // Verify again that we start with "stream"
var hasStartStreamToken = ReadStreamTokenStart(inputBytes, startStreamTokenOffset); var hasStartStreamToken = ReadStreamTokenStart(inputBytes, startStreamTokenOffset);
if (!hasStartStreamToken) if (!hasStartStreamToken)
{ {
return false; return false;
} }
// From the specification: The stream operator should be followed by \r\n or \n, not just \r. // From the specification: The stream operator should be followed by \r\n or \n, not just \r.
if (!inputBytes.MoveNext()) // While the specification demands a \n we have seen files with `garbage` before the actual data
do
{ {
return false; if (!inputBytes.MoveNext())
}
// While the specification demands a \n we have seen files with \r only in the wild.
var hadWhiteSpace = false;
if (inputBytes.CurrentByte == '\r')
{
hadWhiteSpace = true;
inputBytes.MoveNext();
}
if (inputBytes.CurrentByte != '\n')
{
if (!hadWhiteSpace)
{ {
return false; return false;
} }
} while ((char)inputBytes.CurrentByte != '\n');
inputBytes.Seek(inputBytes.CurrentOffset - 1);
}
// Store where we started reading the first byte of data. // Store where we started reading the first byte of data.
long startDataOffset = inputBytes.CurrentOffset; long startDataOffset = inputBytes.CurrentOffset;